SQL Query基于Java中的用户输入

时间:2016-04-25 17:48:31

标签: java jdbc

dis = new DataInputStream(csocket.getInputStream());
int choice = dis.readInt();
Connection conn = MySqlConnect.ConnectDB();
PreparedStatement pst = conn.prepareStatement("Select hostname from clients where C_ID=");
ResultSet rs = pst.executeQuery();

如何将选择放入给定的查询?

1 个答案:

答案 0 :(得分:1)

您可以尝试使用pst.setInt,如下所示:

 PreparedStatement pst=conn.prepareStatement("Select hostname from clients where C_ID=?");
 pst.setInt(1, choice);
 ResultSet rs=pst.executeQuery();
相关问题