
when i call rs.next() in my code it is returning false, though im having valid query to execute and fetch a row from database.how can i resolve this issue.
My code is:
SELECT JOBDESCRIPTION,CATEGORY,OVERVIEW,COUNTRY,STATE,CITY FROM JOB WHERE JOBNAME=? ps.setString(1,jobName);

SQL Select statement with PreparedStatement
import java.sql.*;
public class JdbcPreparedstatementExample {
public static void main(String args[]) {
String name="roseindia";
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root");
String sql ="select * from data where name=?";
PreparedStatement pst = con.prepareStatement(sql);
pst.setString(1, name);
ResultSet rs = pst.executeQuery();
while (rs.next()) {
System.out.println(rs.getString("id"));
System.out.println(rs.getString("name"));
}
} catch (Exception e) {
System.out.println(e);
}
}
}
For more more information, visit the following link:

here i have given my code clearly. In this control didnt go to while loop.so that i couldn set my bean values from resultset.
plz anyone give solution for this.
public retrieveJob(String jobName) {
logger.info("jobname: "+jobName);
Connection connection=null;
PreparedStatement ps = null;
ResultSet r=null;
try{
DaoConnection helper = new DaoConnection();
connection=helper.getConnection();
ps = connection.prepareStatement("SELECT JOBDESCRIPTION,CATEGORY,OVERVIEW,COUNTRY,STATE,CITY FROM JOB WHERE JOBNAME=?");
ps.setString(1,jobName);
r = ps.executeQuery();
logger.info("QUERY EXECUTE :::"+r.next());
while(r.next()){
logger.info("inside while loop....");
logger.info("jobCategory inside HELPER"+r.getString(2));
}}
catch(Exception e){
logger.error("Exception thrown...");
e.printStackTrace();
} finally {
try {
ps.close();
connection.close();
} catch (SQLException e) {
e.printStackTrace();
}}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.