Home Answers Viewqa SQL Resultset Issue in SQL

 
 


Viji Venkat
Resultset Issue in SQL
2 Answer(s)      2 years and 3 months ago
Posted in : SQL

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);
View Answers

February 8, 2011 at 11:59 AM


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:

Select statement with PreparedStatement


February 8, 2011 at 3:54 PM


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();  
  }}

}









Related Pages:
Resultset Issue in SQL
Resultset Issue in SQL  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
SQL exception, Exhausted ResultSet
SQL exception, Exhausted ResultSet  javax.servlet.ServletException: java.sql.SQLException: Exhausted Resultset iam getting this error messege whenever i run my code. what would be the possible reasons
large resultset values - SQL
large resultset values  i have one query which will bring more than one lakh records from database(total records are abt 3 crores). While getting the details i'm getting error like
resultset metadta
resultset metadta  import java.sql.Connection; import... Employee Details Using resultset metadata: "); Connection con = null...(); ResultSet rs = st.executeQuery("SELECT * FROM employee
UNICODE or SQL statement issue - JDBC
UNICODE or SQL statement issue  Hi again............ I have got something new that........... i was using MS Access as the database with my... nothing ...... I had also change my backhand to SQL SERVER but retrieves same
ResultSet
ResultSet   What is a ResultSet
ResultSet
ResultSet  What is a ResultSet
JTable populate with resultset.
(); ResultSet resultSet = statement.executeQuery(sql...JTable populate with resultset.  How to diplay data of resultset...) JTable(Vector data, Vector columneNames) Here is a JTable populate with resultset
ResultSet
ResultSet  I want to retrieve data of unknown datatype from database.how to do it using resultset or Resultsetmetadata.Can you please tell me what... = con.createStatement(); ResultSet rs = st.executeQuery
Executing anonymous pl/sql block and get resultset in Java
Executing anonymous pl/sql block and get resultset in Java  Hello All, I would like to execute the anonymous pl sql block and need to get the resultset object. I got the code which can be done by using cursors inside the pl sql
Spring JdbcTemplate and ResultSet is too slow..
Spring JdbcTemplate and ResultSet is too slow..  Hi.. I am using spring jdbctemplate to fetch the records from oracle database. But it is taking... am using java jdbcTemplate.query(sql, params, RowMapper object) and each record
JSP Paging issue
JSP Paging issue  Hi; what should I have to write insted of "SQLCALCFOUND_ROWS" for MS-SQL database Amrit
Get Column Count using ResultSet in SQL
Get Column Count using ResultSet in SQL   ... of columns in a ResultSet. The ResultSetMetaData object can be obtained by invoking getMetaData() method on ResultSet object. In this program you will see how JDBC
JDBC ResultSet Example
JDBC ResultSet Example: In this example, we are discuss about ResultSet class...) database query results. Through this example you can see how to use ResultSet... and SQL select statement for retrieving data form the database
JDBC ResultSet Delete Row Example
JDBC ResultSet Delete Row Example: Learn how to delete row using ResultSet. We are also used ResultSet object with update capability for delete rows from... type. 3. Create a SQL select query. 4. Execute query using executeQuery
sql - SQL
sql functions with examples  I need sql functions with examples... userid where empname='amardeep'"; ResultSet rs = st.executeQuery(query...("SQL statement is not executed!"); } } catch (Exception e
multiple resultset in one resultset
multiple resultset in one resultset  how to retrive multiple resultsets in one resultset in java.? plz help
Rows Count Example Using JDBC ResultSet
Rows Count Example Using  JDBC ResultSet: In this tutorial you can count the number of rows in the database table using ResultSet. Through this example... will create a Statement object for execute SQL statements as: Statement stmt
sql query - SQL
sql query  hi sir,i have a month and year numbers,when i am enter a month and year in sql query then i want results for 1st day of month to last day...(); ResultSet rs=st.executeQuery("select * from employee where joiningMonth='"+mon
SQL or UNICODE - SQL
SQL or UNICODE   Hi again............ I have got something new... ...... I had also change my backhand to SQL SERVER but retrieves same for UNICODE...(); Statement st=con.createStatement(); ResultSet rs=st.executeQuery("select UNICODE from
SQL query - SQL
SQL query  hi sir/Madam i am using MS Access where i have table like Fees_Struc: Amount (INT) Due_Date (Date) Fees_Pay: Paid(INT..."); Statement st = con.createStatement(); ResultSet rs=st.executeQuery("select Due_Date
database - SQL
database  what is storage capacity of Resultset object for type4 driver
issue on jcombobox
issue on jcombobox  i have JTextfield and JComboBox. there are several values in combobox.when i select a value from combobox how to make textfiled as a combobox.only few values in the combobox need this functionality. need
Open Source SQL
compliant database, browse the data in tables, issue SQL commands etc...Open Source SQL Open Source SQL Clients in Java SQuirreL SQL Client... out common database tasks.     Open Source: Data from MS SQL
jdialogbox issue.
jdialogbox issue.  i have one button.when clicked on it has to show a dialog box.but even click on it several times it has to open dialog box only once. if it is already not opened atleast once,then only it has to open dialog
The cursor in scrollable resultset
The cursor in scrollable resultset   How to move the cursor in scrollable resultset
Update a resultset programmatically
Update a resultset programmatically  How to update a resultset programmatically
JTABLE Issue
to go back for another search. Now issue is -- when I put some input data
Issue with Javascript
Issue with Javascript  Hi I created arrays in javascript in following way var myimages= new Array(); myimages[0]="iphone_pushups.png"; myimages[1]= "cricket.png"; myimages[2]= "july.png"; myimages[3]= "matrix.png
Hiii - SQL
into tab2 values (id,state,location) Resultset rs = stmt.executeUpdate(query1
qurey - SQL
='"+userName+"' and password='"+password+"'"; ResultSet rs = st.executeQuery
BLOB - SQL
){} Blob image = null; Statement stmt = null; ResultSet rs
How do I change the while loop in this code to the range with range list style display page for a resultSet() in jsp?
display page for a resultSet() in jsp?  this is count record code... query = "select count(*) from user_Register"; ResultSet rs = st.executeQuery(query... ex){ System.out.println("SQL statement is not executed!"); } } catch
java,sql
=?"); st.setString(1,value1); ResultSet rs=st.executeQuery(); while(rs.next...); ResultSet res=st.executeQuery(); res.next(); tf7.setText(Integer.toString
Resultset - JSP-Servlet
Resultset  I am writing while(rs.next){} but if resultset is null then it cannot enter in while block. I want,if resultset is null then it will enter into the while block.  Hi friend, A ResultSet object
JDBC Nested Resultset
JDBC Nested Resultset     ...; createStatement ( ) : The create Statement is used to obtain sql object. This object is used to send and execute sql queries in backend of the database
resultset problem - JSP-Servlet
resultset problem  hi I have one problem with resultset? ResultSet rs=st.execute("select subjname,staffname from staffdetails"); while... is java.sql.SQLException: Operation not allowed after ResultSet closed how
Resultset with one to many relationship
Resultset with one to many relationship   Suppose there are 5 tables in database named A,B,C,D and E. A has one to many relationship with B,C,D and D... populate my bean classes from resultset without using hibernate, so
JSP - Resultset - JSP-Servlet
JSP - Resultset  hello sir, how can i count record in jsp. i use resultset in my jsp so in my login form how can i check the username and password is correct or not...?? please reply it's urgent.. thanks

Ask Questions?

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.