快捷导航

不知道是不是是ptmt.execute()的问题

importjava.sql.Connection;importjava.sql.PreparedStatement;importjava.sql.ResultSet;importjava.sql.SQLException;importjava.sql.Statement;importjava.util.ArrayList;importjava.util.List;importcom.JDBC.DBUtil;importmodel.Emps;publicclassEmpsDao{        publicvoidadd(Empsg)throwsException{                Connectionconn=DBUtil.getConnection();                        Stringsql=""+"insertintoemp(eid,enmae,job,mal,deptno)"+"vlues(?,?,?,?,?)";                PreparedStatementptmt=null;                        try{                        ptmt=conn.prepareStatement(sql);        ptmt.execute(sql);        }catch(SQLExceptione){                                e.printStackTrace();                }                                                ptmt.setInt(1,g.getEid());                                                        ptmt.setString(2,g.getEname());                                        ptmt.setString(3,g.getJob());                                                ptmt.setInt(4,g.getMal());                                                ptmt.setInt(5,g.getDeptno());                                                ptmt.execute();        }                publicvoidupdate(){                        }                publicvoiddelect(){                        }                publicListquery()throwsException{                Connectionconn=DBUtil.getConnection();                Statementstmt=conn.createStatement();                        ResultSetrs=stmt.executeQuery("selectename,eidfromemp");                                                Listgs=newArrayList();                                Empsg=null;                                        while(rs.next()){                                                g=newEmps();                                                        g.setEname(rs.getString("ename"));                                                                g.setEid(rs.getInt("eid"));                                                                                                                                                gs.add(g);                }                        returngs;                        }                                        publicEmpsget(){                                        returnnull;        }                        }                                                com.mysql.jdbc.exceptions.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 'vlues(?,?,?,?,?)' at line 1        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:936)        at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2985)        at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1631)        at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1723)        at com.mysql.jdbc.Connection.execSQL(Connection.java:3277)        at com.mysql.jdbc.Connection.execSQL(Connection.java:3206)        at com.mysql.jdbc.Statement.execute(Statement.java:727)        at dao.EmpsDao.add(EmpsDao.java:27)        at action.EmpsAction.main(EmpsAction.java:22)Exception in thread "main" com.mysql.jdbc.exceptions.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 'vlues(1012,'’鱓','–‘',1000,20)' at line 1        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:936)        at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2985)        at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1631)        at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1723)        at com.mysql.jdbc.Connection.execSQL(Connection.java:3283)        at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1332)        at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:882)        at dao.EmpsDao.add(EmpsDao.java:42)        at action.EmpsAction.main(EmpsAction.java:22)

免责声明:本内容仅代表回答者见解不代表本站观点,请谨慎对待。

版权声明:作者保留权利,不代表本站立场。

回复

使用道具 举报

参与会员2

两处错误:

  • values 拼写错误
  • “ptmt.execute(sql);”这句应该去掉

回复

使用道具 举报

你的sql写错了。
回复

使用道具 举报

可能感兴趣的问答

发新帖
TA的信息
  • 会员所属: 注册会员
  • 认证信息: 邮箱认证手机认证
  • 微信访问
  • 手机APP