我创建了一个表单,其中包含用户信息,如姓名,联系人号码,照片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();
}
}
答案 0 :(得分: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
}