首页 > 开发 > MySQL > 正文

JDBC 执行SQL 语句往mysql中插入数据 出现语法错误?

2017-09-08 08:50:40  来源:网友分享

错误提示:
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 '?,?,?,?,?,?,?,current_date(),?,current_date(),?)' at line 1

Connection conn = DBUtil.getConnection();        String sql = ""+            " insert into imooc_goddess"+                " (user_name,sex,age,birthday,email,mobile,"+              "create_user,create_date,update_user,update_date,isdel)"+                " values("+              "?,?,?,?,?,?,?,current_date(),?,current_date(),?)";                PreparedStatement ptmt =  (PreparedStatement) conn.prepareStatement(sql);//...ptmt.execute(sql);`  1. 列表项目`

解决方案

终于找到答案了:
代码中有 : ptmt.execute(sql);有问题,应该是无参数的。
因为在 PreparedStatement ptmt = conn.prepareStatement(sql);已经加载了sql语句。