Reputation: 91
I have a table like this
Signup table
Login_id Address User_type state
1 Ansari s Alaska
2 Rajesh b Rameshwaram
String retrieve_query="select User_type from Signup where State="Alaska";
ResultSet rs1=st.executeQuery(retrieve_query);
String User_type=rs1.getString("User_type");//I expect "S" to be the User_type
But i am getting the following exception
Exception occured java.sql.SQLException: Operation not allowed after ResultSet closed
Upvotes: 2
Views: 1389
Reputation: 167
Try replace you're query with:
String retrieve_query="select User_type from Signup where State='Alaska'";
Upvotes: 0
Reputation: 394026
You're missing rs1.next()
.
String User_type=null;
if (rs1.next())
User_type = rs1.getString("User_type");
Upvotes: 2
Reputation: 172588
You should try to use prepared statement like this:
PreparedStatement ps;
ResultSet rs;
String user_type=null;
ps = con.prepareStatement("select User_type from Signup where State='?'");
ps.setString(1, "Alaska");
rs = ps.executeQuery();
if (rs.next())
user_type = rs.getString("User_type");
Upvotes: 0