Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

J2SE + MySQL Connector/J : Connection Pooling Help Required

843859Oct 31 2006 — edited Nov 1 2006
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
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 29 2006
Added on Oct 31 2006
3 comments
195 views