【问题标题】:SQL Query based on user input in Java [duplicate]基于Java中用户输入的SQL查询[重复]
【发布时间】:2016-04-25 17:48:30
【问题描述】:
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();

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

【问题讨论】:

标签: java jdbc


【解决方案1】:

您可以尝试像这样使用pst.setInt

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-26
    • 2017-09-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多