Can not issue data manipulation statements with executeQuery()
Can not issue data manipulation statements with executeQuery()
无法使用executeQuery()发出数据操作语句。
原因是这句:st.executeQuery() ;
这句应该该成这样子:st.execute() ;
package com.cnblogs.JDBC;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
public class Teststr {
public static void main(String[] args) throws Exception {
Class.forName("com.mysql.jdbc.Driver");
String str1 = "http://127.0.0.1:8848/myWeb/1.html?user=1&age=123&sex=1&like=ppq&like=ps&edu=2";
String[] arr1 = str1.split("\\?");
String str2 = arr1[1];
String[] arr2 = str2.split("\\&");
String url = "jdbc:mysql://localhost:3306/study?characterEncoding = utf8";
Connection connection = DriverManager.getConnection(url, "root", "root");
String sql = "insert into test values(?,?,?,?,?,?)";
PreparedStatement ps = connection.prepareStatement(sql);
for (int i = 0; i < arr2.length; i++) {
String[] arr3 = arr2[i].split("\\=");
ps.setString(i + 1, arr3[1]);
}
ps.execute();
}
}
最后总结:如果你的SQL 语句是诸如update,insert的更新语句,应该用statement的execute()方法,如果用的是statement的executeQuery()就会出现上诉问题
参考:https://blog.csdn.net/cherishme1988/article/details/7399225

浙公网安备 33010602011771号