【问题标题】:Use of the executeUpdate(String) method is not supported on this type of statement此类语句不支持使用 executeUpdate(String) 方法
【发布时间】:2016-07-03 14:10:40
【问题描述】:
PreparedStatement pstmt;
for (int i = 0; i < cnt; i++) {
    String squery = "insert into response(seat_no,question_no,ans_opt,screenshot) values(?,?,?,?)";
    pstmt = con.prepareStatement(squery);
    pstmt.setString(1, cd.getseat());// This is for fetching seat number
    pstmt.setInt(2, i + 1);// This is for question number
    pstmt.setString(3, res[i].getAns());//This is for rensponse answer
    pstmt.setBytes(4, res[i].getScshot());// This is for screenshot byte array
    int num = pstmt.executeUpdate(squery);
    Toast.makeText(getApplicationContext(), String.valueOf(num), Toast.LENGTH_SHORT).show();
}

Sql server 2008 R2 中的我的表

响应表

seat_no nVARCHAR(MAX);

question_no int;

ans_opt 文本;

屏幕截图;

插入时显示错误,如“此类语句不支持使用 executeUpdate(String) 方法”

【问题讨论】:

    标签: java android sql-server-2008 jdbc jtds


    【解决方案1】:

    您在准备语句时已经指定了 SQL:

    pstmt = con.prepareStatement(squery);
    

    你不应该使用Statement.executeUpdate(String) - 而是使用无参数的executeUpdate() 方法:

    int num = pstmt.executeUpdate();
    

    您可能还想考虑在多个调用中重复使用相同的PreparedStatement,或者使用addBatch 一次性执行多个更新。

    【讨论】:

    • 谢谢先生,你让我的大学项目现在可以继续进行
    猜你喜欢
    • 1970-01-01
    • 2023-03-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-23
    • 2020-04-13
    • 2020-12-06
    相关资源
    最近更新 更多