When I run the following from the H2 Console:
SELECT * FROM information_schema.tables;
I get a list of all the tables including the H2 System tables and the
tables I added to H2. When I run the following from a Java program, I
get a list of only the system tables:
try {
Statement statement = getConnection().createStatement();
ResultSet rs = statement.executeQuery("SELECT * FROM
information_schema.tables;");
while(rs.next()){
System.out.print(rs.getString(1) + " ");
System.out.print(rs.getString(2) + " ");
System.out.print(rs.getString(3) + " ");
System.out.print(rs.getString(4) + " ");
System.out.println(rs.getString(5));
}
rs.close();
getConnection().close();
} catch (SQLException e) {
e.printStackTrace();
}
public Connection getConnection(){
if(_connection == null){
try {
_connection = DriverManager.getConnection("jdbc:h2:test", "sa",
"");
} catch (SQLException e) {
e.printStackTrace();
}
}
return _connection;
}
Also, when I try the following I again get a list of only the system
tables, and not my tables:
try {
DatabaseMetaData metadata = getConnection().getMetaData();
String[] types = {"TABLE", "SYSTEM TABLE"};
ResultSet rs = metadata.getTables("TEST", "%", "%", types);
while(rs.next()){
System.out.print(rs.getString(1) + ", ");
System.out.print(rs.getString(2) + ", ");
System.out.print(rs.getString(3) + ", ");
System.out.println(rs.getString(4));
}
rs.close();
getConnection().close();
} catch (SQLException e) {
e.printStackTrace();
}
Any ideas why I can't get a list of the tables I've added to H2 from a
Java app, but I can from the Console?
When I log into the console I used the same jdbc url, username, and
password as I do from the Java app.
H2 was creating a new database instead of connecting to the one I had
running on port 8082. Thanks.
Jay
In the newest version, the default database URL is
jdbc:h2:~/test
So to create databases in the user home directory. To avoid such problems.
I'm not sure if using ~ is clear from a user perspective?
Is it better than using jdbc:h2:test?
Thomas
Jay
On Jul 20, 10:20 pm, "Thomas Mueller" <thomas.tom.muel...@gmail.com>
wrote: