在JAVA中整理MySQL准备的语句

我正在用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。

回答:

以下是我会做:

String insertQuery = "INSERT INTO banlist(name, reason, admin, time, temptime, IP) VALUES (?, ?, ?, ?, ?, ?)"; 

PreparedStatement statement = this.connection.prepareStatement(stringQuery);

statement.setString(1, name); // These values come from your code; dynamic

statement.setString(2, reason);

statement.setString(3, admin);

statement.setString(4, time);

statement.setString(5, tempTime);

statement.setString(6, ip);

int numRowsAffected = statement.executeUpdate();

确保适当地结束你的陈述。

以上是 在JAVA中整理MySQL准备的语句 的全部内容, 来源链接: utcz.com/qa/261660.html

回到顶部