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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

java oracle-sql HELP!

Status
Not open for further replies.

jl3574

Programmer
Jun 5, 2003
76
CA
i have a simple question. i'm connection to the oracle db thru jdbc
i got evertying connect i want to know how i can get the result from an sql statment into a variable?

heres my code
///////////////////////////////////////////////////

Connection con = DriverManager.getConnection("");
Statement s = con.createStatement()
ResultSet rs=s.executeQuery(select max(column from table);
rs.close();
s.close();
con.close();
//////////////////////////////////////////////
//the result statment returns max number in a column
//i want to put that in a var how would i do that?

 
Hi,

there are lots of accessor-methods for the ResultSet like getString(), getInt(), etc. They take the name of the column or the number as parameter.

I guess the following example should work though I haven't tested it:

int maxValue;

Connection con = DriverManager.getConnection("");
Statement s = con.createStatement()
ResultSet rs=s.executeQuery("select max(column) from table");

// rs.next() is necessary to get the first element
while (rs.next()) {
maxValue = rs.getInt(1);
}

rs.close();
 s.close();
 con.close();
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top