这样写,
String sql = "INSERT INTO te (ab) VALUES (?)";
preStmt=conn.prepareStatement(sql);
preStmt.setString(1,"asd");执行SQL时发生异常: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 1 若换一下,不用问号就没问题String sql = "INSERT INTO te (ab) VALUES ('asd')";
preStmt=conn.prepareStatement(sql);
为什么啊,不用问号prepareStatement就没多大意义了,错在哪里?
String sql = "INSERT INTO te (ab) VALUES (?)";
preStmt=conn.prepareStatement(sql);
preStmt.setString(1,"asd");执行SQL时发生异常: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 1 若换一下,不用问号就没问题String sql = "INSERT INTO te (ab) VALUES ('asd')";
preStmt=conn.prepareStatement(sql);
为什么啊,不用问号prepareStatement就没多大意义了,错在哪里?
preStmt=conn.prepareStatement(sql);
preStmt.setString(1,"ab");一用问号就异常,我弄一天了,baidu 和 google 都查遍了,都没明白哪儿出错了,望大家能帮帮我
import java.sql.*;
public class JDBC {
public static void main(String[] args) throws ClassNotFoundException, SQLException {
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "123");
String sql = "INSERT INTO test(name) VALUES (?)";
PreparedStatement pstmt = conn.prepareStatement(sql);
pstmt.setString(1, "liuming");
pstmt.executeUpdate();
pstmt.close();
conn.close();
}
}我这样写了一个,没问题的!
如果后面你执行的时候,用
preStmt.executeUpdate(sql);
是不行的,要用
preStmt.executeUpdate();
pstmt.executeUpdate();
格式是这样的
preStmt.executeUpdate(sql);没怀疑过这里,一直在前面找原因,找了一整天,我郁闷死了
我又长见识了!谢谢大家!!