Re: [dbcp] inconsistently set autocommit
On 9/16/15 10:35 AM, Pruitt, Byron S wrote: > My usual process for learning something is a quick prototype. For setting up > a driver pool with autocommit = false, I implemented the little quickie > prototype below. > > Properties dbProp = new Properties(); > dbProp.put("user", "aUser"); > dbProp.put("password", "aPw"); > dbProp.put("loginTimeout", "35"); > dbProp.put("binaryBatchInsert", "true"); > dbProp.put("autocommit", false); > DataSource dataSource = setupDataSource("myConnectURI", dbProp); //this the > standard example on the website > > Connection conn = dataSource.getConnection(); > System.out.println("autocommit: " + conn.getAutoCommit()); //this prints > out false > > Next. > I moved the above code verbatim to my actual server code. > The first connection I get from the pool has autocommit == false. I return > this connection back to the pool. > But the second time I get a connection from the pool it has autocommit == > true. > > I have no idea why autocommit is set to a different state for the second > connection? I can do a test and then set to autocommit = false, but I would > like to understand the inconsistency. Great question. By default, DBCP's PoolableConnectFactory sets autocommit to true when it returns a connection to the pool. See DBCP-97 for the rationale for this default behavior. This behavior can be modified by setting the enableAutoCommitOnReturn of BasicDataSource or PoolableConnectionFactory to false. You can also use the defaultXxx properties of BDS or PCF to set default properties for connections supplied by the pool. These properties ensure that connections will be restored to a consistent state when the are checked out from the pool, even if client code has mutated them while the connection has been checked out. Phil > > Thanks. > > Steve Pruitt > > - > To unsubscribe, e-mail: user-unsubscr...@commons.apache.org > For additional commands, e-mail: user-h...@commons.apache.org > > > - > To unsubscribe, e-mail: user-unsubscr...@commons.apache.org > For additional commands, e-mail: user-h...@commons.apache.org > > - To unsubscribe, e-mail: user-unsubscr...@commons.apache.org For additional commands, e-mail: user-h...@commons.apache.org
RE: [dbcp] PoolingDataSourceExample with MySQL exception - SOLVED
Note, I set autocommit using .put NonRegisteringDriver iterates through the passed in properties using .getProperty which expects to return a string. Hence, I get a null returned due to the value being a primitive. Details, details. There is a previous post about how to really set autocommit. Had I implemented that before trying to get the pool working, I don't think this problem would have manifested. But, I did learn something. -S -Original Message- From: Pruitt, Byron S [mailto:steve.pru...@hp.com] Sent: Thursday, September 17, 2015 3:40 PM To: Commons Users List Subject: RE: [dbcp] PoolingDataSourceExample with MySQL exception I traced using my IDE's decompiler and it appears to blowing up trying to create a fabric driver, or so it appears. It is not discovering my user and pw properties even though they appear to be passed in via the properties object. I have the MySQL 5.1.36 JConnector. I don't think this is what I need right now, perhaps an earlier version is best. -Original Message- From: Pruitt, Byron S [mailto:steve.pru...@hp.com] Sent: Thursday, September 17, 2015 3:03 PM To: Commons Users List Subject: [dbcp] PoolingDataSourceExample with MySQL exception I got the PoolingDataSourceExample.java up and running using Vertica driver easily enough. I now need to switch to MySQL. I switched out the driver and the uri particulars. But I am getting the exception below. Interesting enough I expected issues with Vertica, but not MySQL. You just never know. Exception in thread "main" java.lang.NullPointerException at java.util.Hashtable.put(Hashtable.java:459) at java.util.Properties.setProperty(Properties.java:166) at com.mysql.jdbc.NonRegisteringDriver.parseURL(NonRegisteringDriver.java:804) at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:316) at java.sql.DriverManager.getConnection(DriverManager.java:664) at java.sql.DriverManager.getConnection(DriverManager.java:208) at org.apache.commons.dbcp2.DriverManagerConnectionFactory.createConnection(DriverManagerConnectionFactory.java:79) at org.apache.commons.dbcp2.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:256) at org.apache.commons.pool2.impl.GenericObjectPool.create(GenericObjectPool.java:868) at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:435) at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:363) at org.apache.commons.dbcp2.PoolingDataSource.getConnection(PoolingDataSource.java:134) at com.hp.mo.tas.pool.test.DriverPoolTest.main(DriverPoolTest.java:58) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140) My setup hasn't really changed much from the working Vertica. Properties dbProp = new Properties(); dbProp.put("user", aUser); dbProp.put("password", aPw); dbProp.put("loginTimeout", "35"); dbProp.put("binaryBatchInsert", "true"); dbProp.put("autocommit", false); String db = "jdbc:mysql://" + "localhost:3306" + "/" + aDb; DataSource dataSource = setupDataSource(db, dbProp); Thanks in advance. -S - To unsubscribe, e-mail: user-unsubscr...@commons.apache.org For additional commands, e-mail: user-h...@commons.apache.org - To unsubscribe, e-mail: user-unsubscr...@commons.apache.org For additional commands, e-mail: user-h...@commons.apache.org - To unsubscribe, e-mail: user-unsubscr...@commons.apache.org For additional commands, e-mail: user-h...@commons.apache.org - To unsubscribe, e-mail: user-unsubscr...@commons.apache.org For additional commands, e-mail: user-h...@commons.apache.org
[dbcp] PoolingDataSourceExample with MySQL exception
I got the PoolingDataSourceExample.java up and running using Vertica driver easily enough. I now need to switch to MySQL. I switched out the driver and the uri particulars. But I am getting the exception below. Interesting enough I expected issues with Vertica, but not MySQL. You just never know. Exception in thread "main" java.lang.NullPointerException at java.util.Hashtable.put(Hashtable.java:459) at java.util.Properties.setProperty(Properties.java:166) at com.mysql.jdbc.NonRegisteringDriver.parseURL(NonRegisteringDriver.java:804) at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:316) at java.sql.DriverManager.getConnection(DriverManager.java:664) at java.sql.DriverManager.getConnection(DriverManager.java:208) at org.apache.commons.dbcp2.DriverManagerConnectionFactory.createConnection(DriverManagerConnectionFactory.java:79) at org.apache.commons.dbcp2.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:256) at org.apache.commons.pool2.impl.GenericObjectPool.create(GenericObjectPool.java:868) at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:435) at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:363) at org.apache.commons.dbcp2.PoolingDataSource.getConnection(PoolingDataSource.java:134) at com.hp.mo.tas.pool.test.DriverPoolTest.main(DriverPoolTest.java:58) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140) My setup hasn't really changed much from the working Vertica. Properties dbProp = new Properties(); dbProp.put("user", aUser); dbProp.put("password", aPw); dbProp.put("loginTimeout", "35"); dbProp.put("binaryBatchInsert", "true"); dbProp.put("autocommit", false); String db = "jdbc:mysql://" + "localhost:3306" + "/" + aDb; DataSource dataSource = setupDataSource(db, dbProp); Thanks in advance. -S - To unsubscribe, e-mail: user-unsubscr...@commons.apache.org For additional commands, e-mail: user-h...@commons.apache.org - To unsubscribe, e-mail: user-unsubscr...@commons.apache.org For additional commands, e-mail: user-h...@commons.apache.org
RE: [dbcp] PoolingDataSourceExample with MySQL exception
I traced using my IDE's decompiler and it appears to blowing up trying to create a fabric driver, or so it appears. It is not discovering my user and pw properties even though they appear to be passed in via the properties object. I have the MySQL 5.1.36 JConnector. I don't think this is what I need right now, perhaps an earlier version is best. -Original Message- From: Pruitt, Byron S [mailto:steve.pru...@hp.com] Sent: Thursday, September 17, 2015 3:03 PM To: Commons Users List Subject: [dbcp] PoolingDataSourceExample with MySQL exception I got the PoolingDataSourceExample.java up and running using Vertica driver easily enough. I now need to switch to MySQL. I switched out the driver and the uri particulars. But I am getting the exception below. Interesting enough I expected issues with Vertica, but not MySQL. You just never know. Exception in thread "main" java.lang.NullPointerException at java.util.Hashtable.put(Hashtable.java:459) at java.util.Properties.setProperty(Properties.java:166) at com.mysql.jdbc.NonRegisteringDriver.parseURL(NonRegisteringDriver.java:804) at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:316) at java.sql.DriverManager.getConnection(DriverManager.java:664) at java.sql.DriverManager.getConnection(DriverManager.java:208) at org.apache.commons.dbcp2.DriverManagerConnectionFactory.createConnection(DriverManagerConnectionFactory.java:79) at org.apache.commons.dbcp2.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:256) at org.apache.commons.pool2.impl.GenericObjectPool.create(GenericObjectPool.java:868) at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:435) at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:363) at org.apache.commons.dbcp2.PoolingDataSource.getConnection(PoolingDataSource.java:134) at com.hp.mo.tas.pool.test.DriverPoolTest.main(DriverPoolTest.java:58) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140) My setup hasn't really changed much from the working Vertica. Properties dbProp = new Properties(); dbProp.put("user", aUser); dbProp.put("password", aPw); dbProp.put("loginTimeout", "35"); dbProp.put("binaryBatchInsert", "true"); dbProp.put("autocommit", false); String db = "jdbc:mysql://" + "localhost:3306" + "/" + aDb; DataSource dataSource = setupDataSource(db, dbProp); Thanks in advance. -S - To unsubscribe, e-mail: user-unsubscr...@commons.apache.org For additional commands, e-mail: user-h...@commons.apache.org - To unsubscribe, e-mail: user-unsubscr...@commons.apache.org For additional commands, e-mail: user-h...@commons.apache.org - To unsubscribe, e-mail: user-unsubscr...@commons.apache.org For additional commands, e-mail: user-h...@commons.apache.org