aspose file tools*
The moose likes JDBC and the fly likes connection problem in jdbc Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "connection problem in jdbc" Watch "connection problem in jdbc" New topic
Author

connection problem in jdbc

raja maharaja
Greenhorn

Joined: Aug 15, 2009
Posts: 7
now iam getting only one error at line number 52 in the below code.
can you tell me should i make another class in which i can declare connection object and if i extend that, can that scope will be available to entire class of this code.
this is my error in the below code,please guide me.


Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30929
    
158

Raja,
The connection is declared in yiour main method. The thread's run method has no way to know about it. How about extracting that logic into a helper method so both main() and run() can obtain a connection?

Also, you'll want to close your resources in a finally block. Right now the code has a connection leak.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
raja maharaja
Greenhorn

Joined: Aug 15, 2009
Posts: 7
Jeanne Boyarsky wrote:Raja,
The connection is declared in yiour main method. The thread's run method has no way to know about it. How about extracting that logic into a helper method so both main() and run() can obtain a connection?

Also, you'll want to close your resources in a finally block. Right now the code has a connection leak.




can you tell me about that helper method how can i write that , so that my logic can be distributed to both main and run methods???
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30929
    
158

raja maharajacan wrote: you tell me about that helper method how can i write that , so that my logic can be distributed to both main and run methods???


I'm not really sure what to say. Creating a method is core Java. Which you presumably know if you are dealing with JDBC and Threads. Unless you got this code from elsewhere of course. In which case, you might want to disclose that so people can point out what to read for the basics.

Basically, you want a static method (so main can call it) that contains the following two lines.


How about you take a stab at it and post here with a question on what you have?

[edited to fix quotes]
 
wood burning stoves
 
subject: connection problem in jdbc