public class JDBC_2 {
public static void main(String[] args) {
try{
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://localhost:3306/xskc";
String user = "root";
String pwd = "mch0dmin";
java.sql.Connection con = DriverManager.getConnection(url, user, pwd);
//java.sql.Statement stmt = con.createStatement();
Statement stmt = null;
String sql = "insert into student values('95005', '張三', '男', 50, 'DC')";
//String sql = "select sno from student";
stmt.executeQuery(sql);
如果執行的是注釋中的select語句,就不會報錯,按時執行insert語句,就出現問題,請大牛幫幫忙!謝謝!
你明顯是錯了,這insert是更改操作,但是你執行的是executeQuery(sql)方法,應該.execute(sql)