Ошибка:com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: У вас есть ошибка в вашем SQL синтаксиса; проверьте руководство, которое соответствует вашей версии сервера MySQL для правильного синтаксиса использовать вблизи «book_id = „DSP123“» в строке 1 в sun.reflect.NativeConstructorAccessorImpl.newInstance0 (Native Method) в sun.reflect.NativeConstructorAccessorImpl. newInstance (NativeConstructorAccessorImpl.java:39) на sun.reflect.DelegatingConstructorAccessorImpl.newInstance (DelegatingConstructorAccessorImpl.java:27) на java.lang.reflect.Constructor.newInstance (Constructor.java:513) на 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:1052) at com. mysql.jdbc.MysqlIO .checkErrorPacket (MysqlIO.java:3609) на com.mysql.jdbc.MysqlIO.checkErrorPacket (MysqlIO.java:3541) на com.mysql.jdbc.MysqlIO.sendCommand (MysqlIO.java:2002) в com.mysql .jdbc.MysqlIO.sqlQueryDirect (MysqlIO.java:2163) на com.mysql.jdbc.ConnectionImpl.execSQL (ConnectionImpl.java:2624) на com.mysql.jdbc.PreparedStatement.executeInternal (PreparedStatement.java:2127) на com.mysql.jdbc.PreparedStatement.executeUpdate (PreparedStatement.java:2427) в com.mysql.jdbc.PreparedStatement.executeUpdate (PreparedStatement.java:2345) в com.mysql.jdbc.PreparedStatement.executeUpdate (PreparedStatement.java : 2330) в Frames.Books.jButton2ActionPerformed (Books.java:424) at Frames.Books.access $ 300 (Books.java:26) в Frames.Books $ 4.actionPerformed (Books.java:181) на javax.swing.AbstractButton.fireActionPerformed (AbstractButton.java:1995) на javax.swing. AbstractButton $ Handler.actionPerformed (AbstractButton.java:2318) в javax.swing.DefaultButtonModel.fireActionPerformed (DefaultButtonModel.java:387) в javax.swing.DefaultButtonModel.setPressed (DefaultButtonModel.java:242) в javax.swing. plaf.basic.BasicButtonListener.mouseReleased (BasicButtonListener.java:236) на java.awt.Component.processMouseEvent (Component.java:6263) на javax.swing.JComponent.processMouseEvent (JComponent.java:3267) на Java. awt.Component.processEvent (Component.java:6028) в java.awt.Container.processEvent (Container.java:2041) на java.awt.Component.dispatchEventImpl (Component.java:4630) на java.awt.Container.dispatchEventImpl (Container.java:2099) на java.awt.Component.dispatchEvent (Component.java:4460) на java.awt.LightweightDispatcher.retargetMouseEvent (Container.java:4574) на java.awt.LightweightDispatcher.processMouseEvent (Container.java:4238) на Java. awt.LightweightDispatcher.dispatchEvent (Container.java:4168) at java.awt.Container.dispatchEventImpl (Container.java:2085) at java.awt.Window.dispatchEventImpl (Window.java:2478) at java.awt. Component.dispatchEvent (Component.java:4460) at java.awt.EventQueu e.dispatchEvent (EventQueue.java:599) на java.awt.EventDispatchThread.pumpOneEventForFilters (EventDispatchThread.java:269) на java.awt.EventDispatchThread.pumpEventsForFilter (EventDispatchThread.java:184) на java.awt.EventDispatchThread. pumpEventsForHierarchy (EventDispatchThread.java:174) в java.awt.EventDispatchThread.pumpEvents (EventDispatchThread.java:169) в java.awt.EventDispatchThread.pumpEvents (EventDispatchThread.java:161) в java.awt.EventDispatchThread.run (EventDispatchThread.java:122)
Кодекс:
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
String bookid = jTextField2.getText();
String doi = "";
Calendar cal = new GregorianCalendar();
doi = doi + cal.get(Calendar.YEAR) + "-" + cal.get(Calendar.MONTH) + "-" + cal.get(Calendar.DAY_OF_MONTH);
String sql = "insert into library.issue values ('"+ bookid + "','librarian','"+ username + "','" + doi + "')";
try
{
int i = st.executeUpdate(sql);
if(i>0)
JOptionPane.showMessageDialog(null,"BOOK IS ISSUED","SUCCESS",JOptionPane.PLAIN_MESSAGE);
else
JOptionPane.showMessageDialog(null,"problem in issuing book","FAILURE",JOptionPane.ERROR_MESSAGE);
bookid = bookid.toUpperCase();
String sql1 = "update library.books set status = " + 1 + "where book_id = '" + bookid + "'";
PreparedStatement pstmt=c.prepareStatement(sql1);
int j= pstmt.executeUpdate() ;
//int j = st.executeUpdate(sql1);
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
О, я понял, это была глупая ошибка. – Manish