I have downloaded a hsqldb.jar and I set to project buildpath,then next I wrote the program
Class.forName("org.hsqldb.jdbc.JDBCDriver");
Connection conn = DriverManager.getConnection(
"jdbc:hsqldb:mem:mydb", "SA", "");
String bookTableSQL = "create table MY_TABLE ("+
" TITLE varchar(256) not null primary key,"+
" AUTHOR varchar(256) not null"+
");";
Statement st = conn.createStatement();
st.execute(bookTableSQL);
System.out.println(st);
String sql = "INSERT INTO MY_TABLE " +
"VALUES ('Mahnaz', 'Fatma')";
st.executeUpdate(sql);
Database and table created successfully. In the next step, I inserted a sample data and get the data is displaying
String sqlsel = "SELECT TITLE,AUTHOR FROM MY_TABLE";
ResultSet rs = st.executeQuery(sqlsel);
//STEP 5: Extract data from result set
while(rs.next()){
//Retrieve by column name
String id = rs.getString("TITLE");
String age = rs.getString("AUTHOR");
//Display values
System.out.print("ID: " + id);
System.out.print(", Age: " + age);
}
My problem is I did not created "mydb" database. Also where can I see the created database and table?
See Question&Answers more detail:os