• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

在JAVA中整理MySQL准备的语句

java 来源:John Smith 3次浏览

我正在用JAVA学习MySQL,并且不理解预准备语句。从抽象我要学习它,我想请她帮忙完成这个代码是“编制说明” :-)在JAVA中整理MySQL准备的语句

String stringQuery = "INSERT INTO banlist (name, reason, admin, time, temptime, IP) VALUES (testNick, testPowod, testAdmin, CURRENT_TIMESTAMP, NOW(), NULL);=?"; 

PreparedStatement statement = this.connection.prepareStatement(stringQuery); 
statement.setString(1, ); // after ' 1, ' we define what we want to get 
ResultSet resultSet = statement.executeUpdate(); 


===========解决方案如下:

String stringQuery = 
    "INSERT INTO banlist (name, reason, admin, time, temptime, IP)" 
    + " VALUES (?, ?, ?, CURRENT_TIMESTAMP, NOW(), NULL)"; 

PreparedStatement statement = this.connection.prepareStatement(stringQuery); 
statement.setString(1, testNick); 
statement.setString(2, testPowod); 
statement.setString(3, testAdmin); 
int inserted = statement.executeUpdate(); 

阅读JDBC tutorial。


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)