猿问

这是怎么回事?

  

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)


qq_柒分醉_03927370
浏览 2585回答 2
2回答

大咪

  //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(),?)";//?相当于占位符;
随时随地看视频慕课网APP

相关分类

MySQL
我要回答