测试 新增女神 方法报错!
错误信息:
Exception in thread "main" 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 'values('小夏', 1, 22, '2016-05-13', 'xiaoxiaxia@163.com', '13988886666', 'ad' at line 1
Hello 各位,以上是错误信息,晚上卡在这里了。按照信息提示,我检查了 sql 语句,但还是找不到错误在哪里。请大家帮我检查下!
以下为 DAO 部分的代码: public class GoddessDao { public void addGoddess(Goddess g) throws Exception { 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(), ?)"; java.sql.PreparedStatement ptmt = conn.prepareStatement(sql); ptmt.setString(1, g.getUser_name()); ptmt.setInt(2, g.getSex()); ptmt.setInt(3, g.getAge()); ptmt.setDate(4, new Date(g.getBirthday().getTime())); ptmt.setString(5, g.getEmail()); ptmt.setString(6, g.getMobile()); ptmt.setString(7, g.getCreate_user()); ptmt.setString(8, g.getUpdate_user()); ptmt.setInt(9, g.getIsdel()); ptmt.execute(); }
以下为 action 部分的代码: public class GoddessAction { public static void main(String[] args) throws Exception { GoddessDao gd = new GoddessDao(); Goddess g1 = new Goddess(); g1.setUser_name("小夏"); g1.setSex(1); g1.setAge(22); g1.setBirthday(new Date()); g1.setEmail("xiaoxiaxia@163.com"); g1.setMobile("13988886666"); g1.setCreate_user("admin"); g1.setUpdate_user("admin"); g1.setIsdel(1); gd.addGoddess(g1);