關於JDK1.7中往mysql中進行帶佔位符的insert語句的報錯。

String sql= " insert into teacher (name,pwd) values    (?,?)";mysql

PreparedStatement stmt=null;sql

stmt=con.prepareStatement(sql);
   
   stmt.setString(1, name);
      stmt.setString(2, pwd);函數

int result=stmt.executeUpdate(sql);//有問題的一行代碼設計

 

如果這麼寫,則會報錯,還查不出是哪裏有問題,報錯信息以下:server

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '?,?)' at line 1io

解決方法,就是將有問題的那行代碼裏的參數去掉就OK了。date

可是原本就以爲要寫兩次參數確實顯得略不科學,函數設計的不科學。jdbc

相關文章
相關標籤/搜索