我有一些问题executeQuery
。我的代码:
try{
String where ="";
String set, sqlque;
int help ;
System.out.println("Laczenie z baza danych ");
Connection conn = DriverManager.getConnection(DB,USER,PASS);
conn.setAutoCommit(false);
Statement stmt = conn.createStatement(
ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
Statement new = conn.createStatement(
ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
temporary = describe.getSelectedItem().toString()+"";
if(!Ab.getText().equals("")){where +=" Ab="+"'"+Ab.getText()+"'AND";};
sqlpytanie="Select ab, product_id from product where describe=?";
PreparedStatement stm1 = conn.prepareStatement(sqlpytanie);
stm1.setString(1, temporary);
ResultSet rs = stm1.executeQuery();
while(rs.next()){
System.out.println("In 1 while");
tmp1 = rs.getString("Ab");
tmp = rs.getString("product_id");
}
help= Integer.parseInt(tmp1) - Integer.parseInt(Ab.getText());
set = "Update Product set ab='"+help+"'"+"where product_id="+tmp;
System.out.println(help);
System.out.println(set);
System.out.println(tmp);
new.executeUpdate(set);
sqlque="Select prices from price where product_id=?";
PreparedStatement stm2 = conn.prepareStatement(sqlque);
stm2.setString(1, tmp);
System.out.println(sqlque);
ResultSet res = stm2.executeQuery();
System.out.println(res);
while(res.next()){
System.out.println("In 2 while");
prices= res.getString("prices ");
}
}
JOptionPane.showMessageDialog(new JFrame()," ab "+ tmp1 + " prices " + prices);
// updateTotal = conn.prepareStatement(updateStatement);
conn.commit();
stmt.close();
new.close();
conn.close();
}
问题在于 second executeQuery
,因为没有结果。Java 没有正确执行这个为什么我会false
从中得到System.out.println(res.next());
?在我的数据库中,一切都很好,它应该显示信息。我究竟做错了什么?