Anjali
Anjali

Reputation: 269

java:After entering id whole information should display

I have created one form, which contain information of user like name, contact no, photo id number, job profile etc. Once he enter all the information, it will store in database. When he login for second time, after entering photo id number whole information should display on the form, without he enters. I am using key typed event for this. I have tried this code, but it is throwing exception as

java.sql.SQLException: Before start of result set

public void show()
{
   try
   {
        String id=photo_id_num.getText();
        System.out.println(""+id);          
        Connect c=new Connect();
        con=c.getConnection();
        Statement stmt=con.createStatement();
        String queryPhotoid = "select *  from tbl_visitor ";
        ResultSet rs1= stmt.executeQuery(queryPhotoid);    
              while (rs1.next()) 
              {
              if(id.equals(rs1.getString(6)))
              {
        // Read values using column name
            String name = rs1.getString(2);
            int contno = rs1.getInt(3);
                String orgname = rs1.getString(4);
                String jobpro = rs1.getString(5);
                String category = rs1.getString(7);
                String date = rs1.getString(8);
                int noofpeople = rs1.getInt(9);
                Blob image = rs1.getBlob(10);
                int extrapeople = rs1.getInt(11);

             System.out.println("Name:"+name+" Contact_no:"+contno+"Org_Name:"+orgname+" Job_profile:"+jobpro+"Category:"+category+"Date:"+date+"No_Of_People:"+noofpeople+"image:"+image+"Having extra people:"+extrapeople);
          }
              }
    }
    catch (SQLException sqlEx)
    {
         sqlEx.printStackTrace();
    }
}

Upvotes: 0

Views: 163

Answers (1)

Jigar Joshi
Jigar Joshi

Reputation: 240928

When you fetch result set the cursor is prior to the first record so you need to take cursor to the first record by executing resultSet.next(), Here in your case you are reading before positioning the cursor

System.out.println("ranu"+rs1.getString(6));  
while (rs1.next());

So you first need to do rs.next() then only you can read the records

So make it as follows

ResultSet rs1= stmt.executeQuery(queryPhotoid);    

while (rs1.next())  {

  System.out.println("ranu"+rs1.getString(6));  
  if(id.equals(rs1.getString(6)))
  {
  // blah blah..
  }
//blah
}

Upvotes: 1

Related Questions