エラーは次のとおりです。
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: SQL 構文にエラーがあります。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) com.mysql.jdbc.Util.getInstance(Util.java:386) で com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1052) で com.mysql.jdbc で。
コードは次のとおりです。
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();
}
}