Thursday, January 26, 2012

JAVA program and HSQLDB

Since the database is up, I was trying to make a simple program that could fetch data from the database.

Assuming there is a table called employee with a column named EMPNAME in the database. This is the code snippet that could achieve the objective.

Class.forName("org.hsqldb.jdbcDriver");
conn = DriverManager.getConnection("jdbc:hsqldb:hsql://localhost/testdb", "SA", "");
stm = conn.createStatement();
rs = stm.executeQuery("select * from employee");
 
while( rs.next() ) {
   System.out.println(rs.getString("EMPNAME"));
}

No comments: