KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ashkelon > Generic


1 package org.ashkelon;
2
3 import java.sql.Connection JavaDoc;
4 import java.sql.ResultSet JavaDoc;
5 import java.sql.SQLException JavaDoc;
6 import java.sql.Statement JavaDoc;
7 import java.util.ArrayList JavaDoc;
8 import java.util.List JavaDoc;
9
10 /**
11  * @author Eitan Suez
12  */

13 public class Generic
14 {
15    public static List JavaDoc listNames(Connection JavaDoc conn, String JavaDoc tablename) throws SQLException JavaDoc
16    {
17       String JavaDoc sql = "select name from " + tablename + " order by name";
18       Statement JavaDoc stmt = conn.createStatement();
19       ResultSet JavaDoc rset = stmt.executeQuery(sql);
20       List JavaDoc pkgs = new ArrayList JavaDoc();
21       while (rset.next())
22       {
23          pkgs.add(rset.getString(1));
24       }
25       rset.close();
26       stmt.close();
27       return pkgs;
28    }
29 }
30
Popular Tags