H2 completely ignores IFEXISTS=false in jdbcUrl - java

I've got the following code to start an H2 daemon and connect to it with Hikari:
// Start H2 daemon
server = Server.createTcpServer("-tcpDaemon").start();
// Connect Hikari to H2 server
HikariConfig hkConfig = new HikariConfig();
hkConfig.setDriverClassName("org.h2.Driver");
hkConfig.setJdbcUrl("jdbc:h2:" + server.getURL() + "/./ghost;MODE=MySQL;IFEXISTS=false");
...
However, even though IFEXISTS is set to false in the JDBC URL, I still get the following exception during pool initialization:
org.h2.jdbc.JdbcSQLNonTransientConnectionException: Database "C:/Users/Cole/IdeaProjects/ghost2/ghost" not found, and IFEXISTS=true, so we cant auto-create it
I tried connecting the 'normal' way with DriverManager to no avail. The same exception was thrown. Is there a different, working way to configure H2 features that I don't know about, or am I doing something wrong?

This appears to be a badly-written error message. See issue #1894 for details.
Strangely enough, this issue doesn't occur in <=1.4.197. The same exact code posted above works. As far as I can tell from #1766, this is a security issue that has been patched.

Related

Hikari: Failed to validate connection because connection is closed

I'm using hikari pool connection through play framework and mariadb client and since I've updated them (play 2.6.5 -> 2.6.6 and mariadb 2.1.1 -> 2.1.2 but not sure it's related) regularly I've got the following error:
HikariPool-1 - Failed to validate connection org.mariadb.jdbc.MariaDbConnection#31124a47 (Connection.setNetworkTimeout cannot be called on a closed connection)
at com.zaxxer.hikari.pool.PoolBase.isConnectionAlive(PoolBase.java:184)
at com.zaxxer.hikari.pool.HikariPool.getConnection(HikariPool.java:172)
at com.zaxxer.hikari.pool.HikariPool.getConnection(HikariPool.java:146)
at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:85)
at play.api.db.DefaultDatabase.getConnection(Databases.scala:142)
at play.api.db.DefaultDatabase.withConnection(Databases.scala:152)
at play.api.db.DefaultDatabase.withConnection(Databases.scala:148)
I've found a related issue here and tried to change the idleTimeout and maxLifetime to 2 and 5 minutes but the error still happened.
I'm using HikariCP 2.7.1, play 2.6.6 and mariadb-java-client 2.1.2
Although you write that you had no success solving this issue by changing the maxLifetime value, I wanted to note that it actually worked for me. Putting its value to 590000 has removed the warnings from my log file.
The maxLifetime (in milliseconds) value of your client should be less than the wait_timeout (in seconds) value of your MySQL instance. This way the client will always terminate the connection before the database tries to. The other way around, the client will try to act upon a closed connection and you will get the above mentioned warnings in your log file.
To see the wait_timeout value of your MySQL instance, you can use the following query:
SHOW VARIABLES like '%timeout%';
The default maxLifetime value for MariaDB should be 28800, but I noticed that 600 can be in place because of MySQL config files being loaded.
I should note that I have no other explicit hikari configuration in place except for a maximum-pool-size of 50.
I got the inspiration from: https://github.com/brettwooldridge/HikariCP/issues/856 by the way. Other very useful resources are: https://github.com/brettwooldridge/HikariCP#configuration-knobs-baby and https://mariadb.com/kb/en/library/server-system-variables/#wait_timeout

JDBC Connection Pool: connections are not recycled after DB restart

I added setMaxActive(8) on org.apache.tomcat.jdbc.pool.PoolProperties. Every time the DB restarts, the application is unusable because the established connections remain. I get the following error:
org.postgresql.util.PSQLException: This connection has been closed
I've tried using some other settings on the pool to no avail...
Thank you for help!
Use the validationQuery property which will check if the connection is valid before returning the connection.
Ref: Tomcat 6 JDBC Connection Pool
This property is available on latest tomcat versions.
Look at this link:
Postgres connection has been closed error in Spring Boot
Very valid question and this problem is usually faced by many. The
exception generally occurs, when network connection is lost between
pool and database (most of the time due to restart). Looking at the
stack trace you have specified, it is quite clear that you are using
jdbc pool to get the connection. JDBC pool has options to fine-tune
various connection pool settings and log details about whats going on
inside pool.
You can refer to to detailed Apache documentation on pool
configuration to specify abandon timeout
Check for removeAbandoned, removeAbandonedTimeout, logAbandoned parameters
Additionally you can make use of additional properties to further
tighten the validation
Use testXXX and validationQuery for connection validity.
My own $0.02: use these two parameters:
validationQuery=<TEST SQL>
testOnBorrow=true

Exception while connecting to DB2 in java using JDBC

I am trying to connect to a db2 database in Java. Below the driver and the connection string and the driver details i am giving
Class.forName("COM.ibm.db2.jdbc.net.DB2Driver");
String url="jdbc:db2://hostname:portnumber/databasename";
sourceConnection=DriverManager.getConnection(url,"username","password");
But I am getting the below exception
"COM.ibm.db2.jdbc.DB2Exception: [IBM][JDBC Driver] CLI0615E Error receiving from socket, server is not responding. SQLSTATE=08S01"
I also tried changing the connection string to
String url="jdbc:db2:hostname:portnumber/databasename";
Still it is resulting the same exception above while trying to get the Connection.
And i have tried the below option also using JDBC app driver
Class.forName("COM.ibm.db2.jdbc.app.DB2Driver");
DB2DataSource db2ds = new DB2DataSource();
db2ds.setServerName("hostname");
db2ds.setPortNumber(portnumber);
db2ds.setDatabaseName("databasename");
db2ds.setUser("username");
db2ds.setPassword("password");
sourceConnection=db2ds.getConnection();
For the above two connection I used the jar "db2java.jar"
And i have tried using the JCC driver:
Class.forName("com.ibm.db2.jcc.DB2Driver");
String url="jdbc:db2://hostname:portnumber/databasename";
sourceConnection=DriverManager.getConnection(url,"username","password");
For this connection i have added the below jars
1)db2jcc.jar
2)db2jcc_license_cu.jar
This time around I am getting the below error,
"com.ibm.db2.jcc.am.go: [jcc][t4][201][11237][3.57.82] Connection authorization failure occurred.
Reason: Security mechanism not supported. ERRORCODE=-4214, SQLSTATE=28000"
I tried to connect to the same db2 source using "Quest for DB2" tool and the connection was successful.
Am i missing something in the code and is it a problem with DB2 drivers or connection string?
Can someone please guide me.
Thanks in advance.
Cause:
If the DB2® instance where InfoSphere Optim Performance Manager is running has the authentication configuration parameter set to DATA_ENCRYPT, you cannot log in to the web console.
Resolving the problem:
Do the following steps:
On the DB2 instance where Optim Performance Manager is running, set the authentication configuration parameter to SERVER by issuing the following command:
db2 update dbm cfg using authentication server
Restart the DB2 instance and InfoSphere Optim Performance Manager.
For more details visit here.
Your first two attempts were not supposed to work. You're using the JCC driver URL format, so it wouldn't be valid for either "net" or "app" drivers, which are deprecated anyway.
Use the JCC driver (com.ibm.db2.jcc.DB2Driver) and the URL format of "jdbc:db2://hostname:portnumber/databasename" and see this technote for the solution to the "Security mechanism not supported" problem. In short, you need to use a supported JDK.

Grails : Undeploy on Glassfish causes connection pool to be no more usable

I'm working on a grails 2.2.1 project running on glassfish 3.1.2.2, using a jndi pooled datasource connected to a postgres 9.2 database.
When I deploy for the first time the application, I have no issues, everything works fine.
But, everytime I undeploy (or redeploy) my application, my connection pool stops working.
If I try to ping using glassfish admin console, I get this error :
Avertissement: RAR8054: Exception while creating an unpooled [test] connection for pool [ sample ],
Connection could not be allocated because: No suitable driver found for
jdbc:postgresql://localhost:5432/sample?loginTimeout=0&socketTimeout=0&prepareThreshold=5&unknownLength=2147483647&loglevel=0&tcpkeepalive=false
Grave: RestResponse.getResponse() donne FAILURE.
endpoint = http://localhost:4848/management/domain/resources/ping-connection-pool.json ; attrs = {id=sample}'
I repeat : my connection pool works fine when I deploy (I have the postgresql driver in "/glassfish/lib", my connection pool is correctly configured, etc.), it's only when I undeploy that I have troubles.
This bug is highly reproductible, I even did a small grails project that reproduces the problem, you only need to have to configure a jndi datasource connected to a "sample" database (jndi/sample) on your glassfish server.
Here is the github link :
https://github.com/fabier/GlassfishJDBCGrailsPostgresql
And the war :
https://www.dropbox.com/s/cb9hmgc6lfabl5x/GlassfishJDBCGrailsPostgresql-0.1.war
and the domains.xml file:
https://www.dropbox.com/s/ljealpfp0zxj2r4/domain.xml
On grails side, my connection to the pool is configured this way:
environments {
production {
dataSource {
dbCreate = "create-drop"
jndiName = "jdbc/sample"
}
}
}
I think this bug is severe, since it kills a connection pool that can be shared amongst other webapps or ears.
For information, I did a bit of research, sensing it might be some sort of class unloader associated with undeployment, I found log4j that could be linked to this problem, so I tryed :
-Dorg.apache.catalina.loader.WebappClassLoader.ENABLE_CLEAR_REFERENCES=false
but it didn't help.
Last point : in fact, postgresql driver is fully unloaded, so that other connection pools using postgresql driver are not usable after an undeploy.
Link to same issue in Grails mailing List:
http://grails.1312388.n4.nabble.com/Undeploy-on-Glassfish-causes-connection-pool-to-be-no-more-usable-td4643041.html
Link to same issue in Glassfish's Jira:
http://java.net/jira/browse/GLASSFISH-20094
Thanks for your help.

How to properly shutdown Embedded Derby database with BoneCP connection pool

With Derby you're specifically suppose to call:
DriverManager.getConnection("jdbc:derby:myDatabase;shutdown=true");
When you want to shutdown the database. However with BoneCP you do:
BoneCPConfig config = new BoneCPConfig();
config.setJdbcUrl("jdbc:derby:myDatabase");
config.setXXX(...);
...
BoneCP connectionPool = new BoneCP(config);
// shutdown connection pool
connectionPool.shutdown();
However with derby you need to call the shutdown command otherwise you can get some errors
So the question is how do I call that shutdown connection string within the BoneCP framework?
In another related newer question, the following appears to be the same cause: "Unless you are running v0.8.1-beta2 or greater, set "disableConnectionTracking" to true in your config."
In other words you need both the derby connection URL as well as the proper config for BoneCP, at least for now...
Please note that you should expect an exception when SUCCESSFULLY shutting down derby: "A successful shutdown always results in an SQLException to indicate that Derby has shut down and that there is no other exception."

Categories

Resources