Thanks.I have removed the main method and modified as you said as follows:
It displays the error:
This method must return a result of type ResultSet
Am i wrong here?
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35232
7
posted
0
Well, right now the code doesn't return a ResultSet; it opens and closes a DB connection, which by itself is not a very useful thing to do. Like I said, I assumed that you want to use this code to run DB queries. If you intended to do something else, let us know what that is.
preethi Ayyappan
Ranch Hand
Joined: Oct 04, 2007
Posts: 518
posted
0
yes.you are correct. i want to use this code to run DB queries in different java codes.How can i return a ResultSet?
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35232
7
posted
0
Thinking about this, what I suggested earlier is actually not going to work, because you can't return a ResultSet if the underlying DB connection is closed. So you may want to keep the connection as an instance field, and then have methods like
The "boolean" result is so that the methods can report success/failure. It's very important to always close DB connections once the code is done with them.