Here I have attached my code, it shows the error like: java.sql.SQLException:
Before start of result set what I am doing wrong here:
String qry = "SELECT * From register ";
stmt = (PreparedStatement) conn.prepareStatement(qry);
rs = stmt.executeQuery();
while (rs.next()) {
String area = rs.getString("city");
if(city.equals(area)){
System.out.println("!!!!!!It matched: " + city);
String qry2="select state from register where city='"+city+"'";
System.out.println(qry2);
stmt = (PreparedStatement) conn.prepareStatement(qry2);
rs = stmt.executeQuery();
String state=rs.getString("state");
System.out.println("state: " + state);
break;
} else {
//System.out.println("No match with: " + area);
}
}
qry? Why is there an if onareawhenareashould be part of the query WHERE clause? Why a second query? Can you updateqryto join with the register table?rsinside of an iteration overrs, you should have aWHEREclause in your SQL query instead of selecting everything.) And additionally, never, never use raw concatenation to build queries with values that come from ANY user (such as might come from acitycolumn). You must, must, must use parameterization. Go research "SQL injection" to find out why.