Index

JDBC

getting a database connection
String url = "jdbc:[database_brand]://[host][:port]/[database][?key1][=value1][&key2][=value2]"
Connection c = DriverManager.getConnection(url);
reading jdbc result set
public class MyResultSetHandler implements ResultSetHandler<DbqResult> {
    public Object handle(ResultSet rs) throws SQLException {
        ResultSetMetaData meta = rs.getMetaData();
        for (int row = 0; rs.next(); row++) {
            for (int col = 1; col <= meta.getColumnCount(); col++) {
		System.out.println(row + ": " + rs.getObject(col));
            }
        }
	return null;
    }
}

metadata

list database entities
try (Connection c = ds.getConnection()) {
	ResultSet rs = c.getMetaData().getTables(null, c.getSchema(), null, null);
return tables and views only
ResultSet rs = c.getMetaData().getTables(null, c.getSchema(), null, new String[] { "TABLE", "VIEW" });
describe table
try (Connection c = ds.getConnection()) {
	ResultSet rs = c.getMetaData().getColumns(null, c.getSchema(), name, null);