Now I have a simple testcase:
import java.sql.*;
import java.util.Date;
import org.h2.jdbcx.JdbcConnectionPool;
public class PooledConnectionTest
{
private static JdbcConnectionPool cp;
public static void createDb()
throws SQLException
{
Connection con = getConnection();
Statement stmt = con.createStatement();
stmt.execute("CREATE TABLE testvalues (value1 INTEGER NOT
NULL)");
con.commit();
stmt.close();
con.close();
}
public static Connection getConnection()
throws SQLException
{
return cp.getConnection();
}
public static void main(String[] args)
throws Exception
{
System.out.println("Start");
cp = JdbcConnectionPool.create("jdbc:h2:~/test/test", "test",
"test");
cp.setMaxConnections(Integer.MAX_VALUE);
createDb();
System.out.println("DB created");
Connection con = getConnection();
cp.dispose();
Statement stmt = con.createStatement();
System.out.println("Shutdown...");
stmt.execute("SHUTDOWN");
try
{
stmt.close();
con.close();
}
catch (SQLException sqe)
{
}
stmt = null;
con = null;
cp = null;
Thread.sleep(2000L);
System.out.println(new Date() + " Run GC");
// run the garbage collection
Runtime.getRuntime().gc();
Thread.sleep(2000L);
// Reopen the database
cp = JdbcConnectionPool.create("jdbc:h2:~/test/test", "test",
"test");
cp.setMaxConnections(Integer.MAX_VALUE);
Connection con2 = getConnection();
Statement stmt2 = con2.createStatement();
String query = "SELECT * FROM testvalues WHERE value1 < 1000";
ResultSet rs = stmt2.executeQuery(query);
rs.close();
stmt2.close();
con2.close();
rs = null;
stmt2 = null;
con2 = null;
cp.dispose();
cp = null;
System.out.println(new Date()
+ " The error 'connection not closed' appears int the
test.trace.db file");
Thread.sleep(60000L);
System.out.println("Goodbye");
}
}
The testcase creates a database with a PooledConnection.
All open connections are closed and the last connection issues a
"SHUTDOWN" command.
This connection is also closed which throws an SQLException. That's
ok.
The garbage collector should run then.
The database is reopened and a simple query is performed.
The connection is closed and the connection pool is disposed.
Anyhow there should be no connection which is not explicitely closed
an exception appears in the test.trace.db file that complains about
the last connection would not have been closed.
Is this is a bug in the H2 pooled connection or is there an error in
my code?
Uli
--
You received this message because you are subscribed to the Google Groups "H2
Database" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/h2-database?hl=en.