gpt4 book ai didi

java - 集合值没有在传递的查询中迭代?

转载 作者:太空宇宙 更新时间:2023-11-04 07:08:26 24 4
gpt4 key购买 nike

下面是我的代码..

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 并且我想要所有收据编号的相同详细信息。

最佳答案

您可能提出了异常(exception)。请尝试使用以下代码:

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

关于java - 集合值没有在传递的查询中迭代?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20993845/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com