Two Laptop Bag*
The moose likes JDBC and the fly likes How i can reach Resultset Connection variables outside Class or from inner method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "How i can reach Resultset Connection variables outside Class or from inner method" Watch "How i can reach Resultset Connection variables outside Class or from inner method" New topic
Author

How i can reach Resultset Connection variables outside Class or from inner method

ozhan kaya
Greenhorn

Joined: Mar 19, 2009
Posts: 13
I don't know I telled true or not(i know resultset not a variable).But after see my code you can understand.I have a connect database class.I have a method for connection and execute queries.



I plan use a lot of different methods using this connection.But i don't want to use Classforname,Connection codes in every single method.I tryed to make a constructor but did not worked.I mean how i can make this possible and how i can reach Cnctdb , sqldb ... from another class(i succesed in swing objects but failed in connection).

Thanks in advance...
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3816

You should move that, "getting a connection" code in to factory class which will initialize when the application starts and can be used to get connections.

Here is just a brief guide to get started. You may add many features/functions to enhance or make it more usable later.



And You know how to use this class in client code right ?

SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
ozhan kaya
Greenhorn

Joined: Mar 19, 2009
Posts: 13
Thanks a lot Vijitha Kumara.I even tryed this > static Resultset
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
ozhan kaya wrote:I tryed to make a constructor but did not worked.

It will work if you code it the right way and removed the 'static' modifier.
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
ozhan kaya wrote:Thanks a lot Vijitha Kumara.I even tryed this > static Resultset

Very bad idea. Go back to your basic Java book/tutorial and carefully learn what the 'static' modifier does.
 
wood burning stoves
 
subject: How i can reach Resultset Connection variables outside Class or from inner method
 
Similar Threads
basic SQL connection steps
Need help with using Greek letters read in from file
Prepared statment executeQuery() error.
iterating with a scriptlet, can't get the values into js arr
JSP attendance management project error