Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Error in java sql

I am running the following code in JSP and I am receiving the error message:
"sun.jdbc.odbc.JdbcOdbcResultSet@1627086 "

String sql1 = "SELECT employeeID, groupPolicyNo FROM employee WHERE employeeID = 9;";
Statement stmtAdmin =con.createStatement();
ResultSet res = stmtAdmin.executeQuery(sql1);
out.println(res);


// the next query finds all the employees who have that group policy no.
String sql2 = "SELECT employeeID, groupPolicyNo FROM employee WHERE groupPolicyNo = "+res+" ;";
Statement stmt =con.createStatement();
ResultSet rs = stmt.executeQuery(sql2);
out.println(rs);

These queries are running perfectly in the database but not on the browser,
Can any one shed some light?
:o
[762 byte] By [Maria Modeste] at [2007-11-11 6:55:00]
# 1 Re: Error in java sql
I assume that you are using an Applet in the browser? And it is running in the browser's Java plugin.
If so, there might be error messages in the browser's Java console. Find the browser's menuitem that displays the Java console and copy the error messages from there to here.
Norm at 2007-11-11 22:39:57 >
# 2 Re: Error in java sql
I may be missing some features here... but it seems to me that you are concatenating
the string representation of a ResultSet instance to your second query string :confused:.

I would code it like:

// the next query finds all the employees who have that group policy no.
String sql2 = "SELECT employeeID, groupPolicyNo FROM employee WHERE groupPolicyNo = "+res.getString("groupPolicyNo")+" ;";

And whats with that semicolon inside the query string ?
sjalle at 2007-11-11 22:41:02 >
# 3 Re: Error in java sql
Yes, I am concatenating a string representation of a ResultSet inside the second record. No I am not using an applet in a browser. But I have decided to re-write the code in pure Java instead of JSP.

Thanks for the help!
Maria Modeste at 2007-11-11 22:42:06 >
# 4 Re: Error in java sql
A string representation of a java object has no business in a query string, unless it was in a (weird) database of java references strings.
sjalle at 2007-11-11 22:43:00 >