Hi everyone,
I've searched through this massive forum for previous similar posts and haven't found much with respect to JDBC usage and standard J2SE apps - seems the most common use of connection pooling is for JSP and the like.
The application in this case, is that of a standard Swing program, which must interact with MySQL quite heavily. I have the gizmo working well at present, but it's dire time to tackle a means to make the connection model more efficient - I believe that connection pooling would be the solution I require. I need to eliminate connection lag if possible, and have some means to remove stale connections (connections that expire because of MySQL's interactive-timeout for example).
Right now, I'm simply connecting like this using a Spin (spin.sourceforge.net) invocation class:
private class SingleConnection implements ThrowableDataObject{
public Object getData() throws Exception{
Assert.isNotEDT();
StringBuffer b = new StringBuffer();
synchronized( this ){
b.append( "jdbc:mysql://" );
b.append( hostname );
b.append( "/" );
b.append( database );
Class.forName( "com.mysql.jdbc.Driver" );
DriverManager.setLoginTimeout( 20 );
Connection c = DriverManager.getConnection( b.toString() + "?zeroDateTimeBehavior=convertToNull&useUnicode=true&characterEncoding=utf8", info );
Statement s = c.createStatement();
s.executeQuery( "SET NAMES 'utf8'" );
s.executeQuery( "SET SESSION sql_mode=''" );
s.close();
return c;
}
}
}
It was in the end a band-aid solution that needs to get tackled, but my knowledge is admittedly limited in this regard, and so I turn to the experts!! What should be my first step toward replacing these single-demand connections? Are there any pool managers built into Java that I should look into?
Your kind guidance, is most appreciated.
Regards.
Alex