public static void Student(int a,int rNo,String nm,String sn,int id,int age,Date bd,String gen,String nati,String rg,String fee,String insti,String crs,String sd,String email,int phn,String add,byte[]img) throws ClassNotFoundException, SQLException {
String sql[]={"INSERT INTO studentreg (regNo,name,sname,idNo,age,birthD,gen,national,relegion,fee,institute,pro,sDay,eMail,phnNo,address,img) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);"
,"UPDATE studentreg SET ( regNo , name , sname , idNo , age , birthD , gen , national , relegion , fee , institute , pro , sDay , eMail , phnNo, address , img ) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) WHERE regNo = '+rNo+'" };
if(con==null)
connect();
psm=con.prepareStatement(sql[a]);
psm.setInt(1,rNo);
psm.setString(2, nm);
psm.setString(3, sn);
psm.setInt(4, id);
psm.setInt(5, age);
psm.setDate(6, bd);
psm.setString(7, gen);
psm.setString(8, nati);
psm.setString(9, rg);
psm.setString(10, fee);
psm.setString(11, insti);
psm.setString(12, crs);
psm.setString(13, sd);
psm.setString(14, email);
psm.setInt(15, phn);
psm.setString(16, add);
psm.setBytes(17, img);
psm.executeUpdate();
----------错误就是这个
- Dec 28, 2014 1:25:28 PM GUI.studentInfo btnUpdateActionPerformed
SEVERE: null
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 '(regNo,name,sname,idNo,age,birthD,gen,national,relegion,fee,institute,pro,sDay,e' at line 1
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.Util.getInstance(Util.java:386)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1054)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4187)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4119)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2570)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2731)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2815)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2155)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2458)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2375)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2359)
at Model.DbConnect.Student(DbConnect.java:59)
at Model.studentEdit.studentGet(studentEdit.java:97)
at GUI.studentInfo.btnUpdateActionPerformed(studentInfo.java:1006)
at GUI.studentInfo.access$1400(studentInfo.java:24)
at GUI.studentInfo$15.actionPerformed(studentInfo.java:831)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2346)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
at java.awt.Component.processMouseEvent(Component.java:6527)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
at java.awt.Component.processEvent(Component.java:6292)
at java.awt.Container.processEvent(Container.java:2234)
at java.awt.Component.dispatchEventImpl(Component.java:4883)
at java.awt.Container.dispatchEventImpl(Container.java:2292)
at java.awt.Component.dispatchEvent(Component.java:4705)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4898)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4533)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4462)
at java.awt.Container.dispatchEventImpl(Container.java:2278)
at java.awt.Window.dispatchEventImpl(Window.java:2739)
at java.awt.Component.dispatchEvent(Component.java:4705)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:746)
at java.awt.EventQueue.access$400(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:697)
at java.awt.EventQueue$3.run(EventQueue.java:691)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.awt.EventQueue$4.run(EventQueue.java:719)
at java.awt.EventQueue$4.run(EventQueue.java:717)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:716)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
答案 0 :(得分:2)
您的第二个SQL查询中显然有错误:
UPDATE studentreg SET ( regNo , name , sname , idNo , age , birthD , gen , national , relegion , fee , institute , pro , sDay , eMail , phnNo, address , img ) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) WHERE regNo = '+rNo+
必须以此形式定义更新:
UPDATE studentreg SET regNo = ?, name = ?, ...
等等......
答案 1 :(得分:0)
您正在使用类似插入的更新:
UPDATE studentreg SET ( regNo , name , sname , idNo , age , birthD , gen , national , relegion , fee , institute , pro , sDay , eMail , phnNo, address , img ) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) WHERE regNo = '+rNo+'"
您可以执行以下操作:
UPDATE Table SET regNo = i.regNo, name = i.Name, ...
FROM (SELECT Col1, Col2 FROM other_table WHERE regNo = 'rNo') i