如何为preparedStatement设置值?

时间:2013-12-14 03:40:27

标签: java

我有一个prepareStatement,select = "Select * From Withdraw where CustID = ? AND AccountNo = ?;"; 如何将值从用户输入传递到它?

1 个答案:

答案 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,第二个为?

为2
"... CustID = ? AND AccountNo = ? ..."
              1                 2