以下是我的代码..
while(obt.hasNext()){
try{
Object itrvalue = obt.next();
String sql2 ="select entryDt,Student_Name,Class_Div_Name,ReceiptNo from test where ReceiptNo = '"+itrvalue+"'";
System.out.println("Receipt No --"+itrvalue);
stat = con.prepareStatement(sql2);
rs=stat.executeQuery();
rs.next();
Date datevalue = rs.getDate(1);
String name = rs.getString(2);
String CDN = rs.getString(3);
String RNO = rs.getString(4);
System.out.println("Date is ---"+datevalue);
System.out.println("Student Name ---"+name);
System.out.println("Coloumn Div No ---"+CDN);
System.out.println("Receipt No ---"+RNO);
rs.close();
}
catch(Exception ex){};
}
输出: -
Receipt No --S00000001234
Date is ---2013-06-10
Student Name ---ABC XYZ
Coloumn Div No ---VI - C
Receipt No ---S00000001234
Receipt No --S00000001234
Receipt No --S00000001235
Receipt No --S00000001236
Receipt No --S00000001237
Receipt No --S00000001238
Receipt No --S00000001239
每个迭代值都会发生变化。但是在当前的SQL查询中,它只是传递了第一个值剩余的迭代值,但是没有在SQL查询中传递。根据输出,您可以看到我只收到了数据S00000001234
,我想要所有收据号的相同详细信息。
答案 0 :(得分:1)
您可能已经提出异常。请尝试使用此代码:
String sql2 = "select entryDt,Student_Name,Class_Div_Name,ReceiptNo from test where ReceiptNo = ?";
PreparedStatement stat = con.prepareStatement(sql2);
try {
while (obt.hasNext()) {
try {
Object itrvalue = obt.next();
System.out.println("Receipt No --" + itrvalue);
stat.setObject(1, itrvalue);
rs = stat.executeQuery();
rs.next();
Date datevalue = rs.getDate(1);
String name = rs.getString(2);
String CDN = rs.getString(3);
String RNO = rs.getString(4);
System.out.println("Date is ---" + datevalue);
System.out.println("Student Name ---" + name);
System.out.println("Coloumn Div No ---" + CDN);
System.out.println("Receipt No ---" + RNO);
rs.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
} finally {
if (stat != null) {
stat.close();
}
}