Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Method for repeated results

Status
Not open for further replies.

evergrean100

Technical User
Dec 1, 2006
115
US
I have the same results with SQL statement in my Database class file several times and was wondering if I can make it into a method?

Code:
public somemethod()
{
ResultSet results = null;
Statement statement = null;
...
//next two lines are repeated several times in different methods in this class file:
results = statement.executeQuery("select sport from typetable");
results.next();
....

My attempt outputs no data. Please advise.
Code:
public boolean mymeth()
{
    try {
    ResultSet results = null;
Statement statement = null;
    results = statement.executeQuery("select sport from typetable");
     boolean mydata = results.next();
     }
     catch(Exception e)
     {
     }
     return mydata;
}


public somemethod()
{
ResultSet results = null;
Statement statement = null;
...
mymeth();
....
 
there are a few errors with your code, eg

1) in your code, you set statement = null, then without getting a database connection, you try to execute SQL?

2) assuming you have gotten a database connection, you declared mydata in the try block but you try to return mydata outside the try block?
 
Try not hiding your exceptions, you will see that lowbk is rigth.

Cheers,
Dian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top