aspose file tools*
The moose likes JDBC and the fly likes returning a result set Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "returning a result set" Watch "returning a result set" New topic
Author

returning a result set

justin wall
Greenhorn

Joined: Jul 30, 2001
Posts: 8
I'm having trouble returning a resultset in this method. It says that my resutset might not have been initialized. Thanks,
Justin
public static ResultSet runQuery(String q)
{
ResultSet RS;
try
{

// The newInstance() call is a work around for some
// broken Java implementations

Class.forName("org.gjt.mm.mysql.Driver").newInstance();

}
catch (Exception E)
{
System.err.println("Unable to load driver.");
E.printStackTrace();
}
try
{
// jdbc:mysql://[hostname][:port]/dbname[?param1=value1][¶m2=value2]...
Connection C = DriverManager.getConnection(
"jdbc:mysql://xx.xx.com/tparser?user=xxxl&password=xxxxi");

// Do something with the Connection
try
{
// Use some connection we've already created

Statement Stmt = C.createStatement();

RS = Stmt.executeQuery(q);



/* Clean up after ourselves*/
RS.close();
Stmt.close();
C.close();
}
catch (SQLException E)
{
System.out.println("SQLException: " + E.getMessage());
System.out.println("SQLState: " + E.getSQLState());
System.out.println("VendorError: " + E.getErrorCode());
}

}
catch(SQLException E)
{
System.out.println("SQLException: " + E.getMessage());
System.out.println("SQLState: " + E.getSQLState());
System.out.println("VendorError: " + E.getErrorCode());
}


return RS;

}
------------------
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
Try ResultSet RS = null;
Bosun

Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
justin wall
Greenhorn

Joined: Jul 30, 2001
Posts: 8
Thanks! That was it. In Java, do you have to initalize every variable with a value when you declare it?
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
Local variables have to be initialized before they are used. This is local because it's declared within a method.

Bosun
 
 
subject: returning a result set