Return a ResultSet from a method
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Alistair_Sedwell
Posted On:   Thursday, April 11, 2002 03:34 AM

Hi, I'm trying to return a SQL ResultSet from a method but it just returns NULL. private Driver driver; private Connection conn = null; static String driverUsed = "oracle.jdbc.driver.OracleDriver"; static String serverAddress = "jdbc:oracle:thin:dummydata/dummydata@uksap10:1521:evoseek"; private ResultSet rset; public ResultSet SQLQuery (String sql){ try{ driver = (Driver)Class.forName(driverUsed).newInstance(); conn = DriverManager.getConnection(serverAddress); Statement stmt = conn.createStatement (); ResultSet rset = stmt.executeQuery (sql); } catch (Exception ex) { ex.printStac   More>>

Hi,

I'm trying to return a SQL ResultSet from a method but it just returns NULL.

			
private Driver driver;
private Connection conn = null;
static String driverUsed = "oracle.jdbc.driver.OracleDriver";
static String serverAddress = "jdbc:oracle:thin:dummydata/dummydata@uksap10:1521:evoseek";
private ResultSet rset;

public ResultSet SQLQuery (String sql){

try{
driver = (Driver)Class.forName(driverUsed).newInstance();
conn = DriverManager.getConnection(serverAddress);
Statement stmt = conn.createStatement ();
ResultSet rset = stmt.executeQuery (sql);

}
catch (Exception ex) {
ex.printStackTrace();
}
return rset;

}


Can anyone tell me what i'm doing wrong ?

Thanks in advance

Alistair    <<Less

Re: Return a ResultSet from a method

Posted By:   Aron_Tunzi  
Posted On:   Thursday, April 11, 2002 03:44 AM

The problem is easy. You return the this.rset and not the rset defined in the method.


The right code is:

private Driver driver;
private Connection conn = null;
static String driverUsed = "oracle.jdbc.driver.OracleDriver";
static String serverAddress = "jdbc:oracle:thin:dummydata/dummydata@uksap10:1521:evoseek";
private ResultSet rset;

public ResultSet SQLQuery(String sql){

ResultSet rset = null;

try{
driver = (Driver)Class.forName(driverUsed).newInstance();
conn = DriverManager.getConnection(serverAddress);
Statement stmt = conn.createStatement ();
rset = stmt.executeQuery (sql);
} catch (Exception ex) {
ex.printStackTrace();
}
return rset;
}

Bye, Aron
About | Sitemap | Contact