This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Hi, I am using the code below to create a jdbc connection to an MS SQL server. It works fine, but I was trying to make a static connection, so the app would only have one connection during its use. I noticed however that everytime I click on the connect button in my swing app, I get a new connection. Am I not understanding "static connection," or does my code not properly create a static connection?
[ April 21, 2006: Message edited by: stu derby ] [ April 21, 2006: Message edited by: stu derby ]
Joined: Jul 20, 2005
As simple as checking to see if the Connection was null before creating a new one... Thanks Stu
Joined: Dec 15, 2005
Originally posted by Eric Gero: As simple as checking to see if the Connection was null before creating a new one... Thanks Stu
I realized later that the "synchronized" on the method isn't needed; a) your application is single-threaded, and b) more than one thread can't use the same connection at a time anyway (bad things happen if you try).