为了账号安全,请及时绑定邮箱和手机立即绑定

这是怎么回事?

这是怎么回事?

qq_柒分醉_03927370 2016-09-26 21:19:18
  package com.jdbc.dao;import java.sql.Connection;import java.sql.Date;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;import java.util.ArrayList;import java.util.List;import com.jdbc.Jdbc;import com.jdbc.model.Goddess;import com.mysql.fabric.xmlrpc.base.Data;public class GoddessDao {         public void addGoddess(Goddess g) throws Exception {        Connection conn =  Jdbc.getConnection();        String sql =""+"insert  into imooc_goddess"+"(user_name,sex,age,email,birthday,mobile,"                               +"create_user,create_date,update_user,update_date,isdel,)"                               +"values(" + "?,?,?,?,?,?,?,current_date(),?,current_date(),?)";//?相当于占位符;        PreparedStatement  ptmt =    conn.prepareStatement(sql);                 ptmt.setString(1, g.getUser_name());        ptmt.setInt(2, g.getSex());        ptmt.setInt(3, g.getAge());        ptmt.setString(4, g.getEmail());        ptmt.setDate(5 ,  new Date(g.getBirthday().getTime()));        ptmt.setString(6, g.getMobile());        ptmt.setString(7, g.getCreate_user());        ptmt.setString(8, g.getUpdate_user());        ptmt.setInt(9, g.getIsdel());                          ptmt.execute();                                           }    public void updateGoddess(){        }    public void delGoddess(){        }    public List<Goddess> query() throws Exception {     Connection conn =  Jdbc.getConnection();     Statement stat = conn.createStatement(); ResultSet rs = stat.executeQuery("select  user_name,age  from imooc_goddess"); List<Goddess> gs = new ArrayList<Goddess>(); Goddess g = null; while (rs.next()) { g=new Goddess(); g.setUser_name(rs.getString("user_name")); g.setAge(rs.getInt("age")); gs.add(g); }     return gs;    }    public Goddess get(){     return null;        }}控制台异常: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,'xiaoxia@qq.com','2016-09-26','13254685481','lee',current_' at line 1 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) at java.lang.reflect.Constructor.newInstance(Constructor.java:513) at com.mysql.jdbc.Util.handleNewInstance(Util.java:404) at com.mysql.jdbc.Util.getInstance(Util.java:387) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:942) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3966) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3902) at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2526) at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2673) at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2549) at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1861) at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1192) at com.jdbc.dao.GoddessDao.addGoddess(GoddessDao.java:35) at com.action.GoddessAction.main(GoddessAction.java:33)
查看完整描述

2 回答

已采纳
?
大咪

TA贡献785条经验 获得超332个赞

  //SQL语句异常,说明写错了
  
     String sql =""+"insert  into imooc_goddess"+"(user_name,sex,age,email,birthday,mobile,"
                               +"create_user,create_date,update_user,update_date,isdel)"   //这行我觉得你最后那个逗号是多余的
                               +"values(" + "?,?,?,?,?,?,?,current_date(),?,current_date(),?)";//?相当于占位符;


查看完整回答
反对 回复 2016-09-26
  • 2 回答
  • 0 关注
  • 2573 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信