package gimped; import java.sql.*; import java.util.*; //import java.lang.*; /** * @author benny * */ public class ConnectionEngine { public Connection connection; public ConnectionEngine() { } public Connection buildconnection(String connstring, String DBpackage) throws SQLException { //onnection conn = null; try{ Class.forName(DBpackage).newInstance(); connection = DriverManager.getConnection(connstring); } catch(InstantiationException inst) { System.out.println("Could not instantiate db connection"); } catch(IllegalAccessException i) { System.out.println("ILLEGAL ACCESS CALLING THE POLICE"); } catch(ClassNotFoundException c) { System.out.println("JDBC DRIVER NOT FOUND"); } catch(SQLException e){ System.out.println("Could not connect to:" + connstring); throw new SQLException(); } return connection; } public List gettables() throws SQLException { List tables = null; ResultSet rs = null; try { DatabaseMetaData dbm = connection.getMetaData(); String types[] = {"TABLE"}; rs = dbm.getTables(null, null, "", types); int i = 0; while(rs.next()) { String table = rs.getString("TABLE_NAME"); //System.out.println(table); <- works just fin //tables.add(table); <- fucking throws java.lang.NullPointerException //System.out.println(tables.get(i)); i++; } } catch (NullPointerException n) { n.printStackTrace(); } catch (SQLException e) { throw new SQLException(); } finally { if(rs!=null) { try { rs.close(); } catch(SQLException e) { } } } return tables; } public static void main(String[] args) { } }