Win a copy of Java Challengers this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • paul wheaton
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • Mikalai Zaikin
  • Himai Minh

connection problem in jdbc

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.


 
author & internet detective
Posts: 40536
825
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 40536
825
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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]
 
reply
    Bookmark Topic Watch Topic
  • New Topic