我有一个prepareStatement,select = "Select * From Withdraw where CustID = ? AND AccountNo = ?;";
如何将值从用户输入传递到它?
答案 0 :(得分:2)
String query = "Select * From Withdraw where CustID = ? AND AccountNo = ?";
PreparedStatment preparedStatement = conn.prepareStatement(query);
preparedStatement.setString(1, aString);
preparedStatement.setString(2, anotherString);
rset = preparedStatement.executeQuery();
如果您使用整数,则有setInt(1, someInt)
1参数是?
。第一个?
为1,第二个为?
"... CustID = ? AND AccountNo = ? ..."
1 2