• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

returning a result set

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

}
------------------
 
Ranch Hand
Posts: 1514
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try ResultSet RS = null;
Bosun
 
justin wall
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks! That was it. In Java, do you have to initalize every variable with a value when you declare it?
 
Bosun Bello
Ranch Hand
Posts: 1514
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Local variables have to be initialized before they are used. This is local because it's declared within a method.

Bosun
 
reply
    Bookmark Topic Watch Topic
  • New Topic