• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

connection problem in jdbc

 
raja maharaja
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34839
369
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
raja maharaja
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34839
369
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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]
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic