jdbc mysql executeUpdate不能正常工作

时间:2018-01-20 06:33:32

标签: java mysql jdbc

PreparedStatement  stmt1 = con.prepareCall("update khol SET emailcnf =  'ya' where khol.id = 
     (SELECT guiid.id FROM guiid WHERE guiid.gchbi = 'htg1' and guiid.typ = 'reg')");

System.out.println("rows COUNT "+stmt1.executeUpdate());

stmt1.close();

输出是:

  

行COUNT 0

0由executeUpdate返回并且当我直接运行相同的语句在Mysql中它工作正常。

1 个答案:

答案 0 :(得分:0)

您应该使用con.prepareStatement()代替con.prepareCall()

请查看以下链接,以帮助您了解createStatement() prepareSatement()prepareCall()

之间的区别

http://javaconceptoftheday.com/statement-vs-preparedstatement-vs-callablestatement-in-java/

以下内容应该有效:

PreparedStatement  stmt1 = con.prepareStatement("update khol SET emailcnf =  'ya' where khol.id = 
            (SELECT guiid.id FROM guiid WHERE guiid.gchbi = 'htg1' and guiid.typ = 'reg')");

System.out.println("rows COUNT "+stmt1.executeUpdate());

stmt1.close();