0

我创建了一个表单,其中包含用户的信息,如姓名、联系方式、照片 ID 号码、工作资料等。一旦他输入所有信息,它将存储在数据库中。当他第二次登录时,输入照片身份证号码后,整个信息应该显示在表格上,而不是他输入。我为此使用键输入事件。我试过这段代码,但它抛出异常

java.sql.SQLException:结果集开始之前

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

1 回答 1

1

当您获取结果集时,光标位于第一条记录之前,因此您需要通过执行将光标移至第一条记录resultSet.next(),在您的情况下,您在定位光标之前正在阅读

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

所以你首先需要做rs.next()的只有你可以阅读记录

所以让它如下

ResultSet rs1= stmt.executeQuery(queryPhotoid);    

while (rs1.next())  {

  System.out.println("ranu"+rs1.getString(6));  
  if(id.equals(rs1.getString(6)))
  {
  // blah blah..
  }
//blah
}
于 2012-05-31T09:37:47.060 回答