このプログラムを実行すると、エラーになってしまいました。エラーコードについても調べてみたのですが、いまいちよくわからず、同じような形式のSELECT文では正常にデータベースに接続されて、思った通りの実 行結果になるのですが、これはうまくいきません。 ※JDBCのプログラムです。 ※データベースにコマンドライン引数を用いて、INSERTしようとしています。 ※コマンドライン引数を指定した上で実行し、成功した場合は「1件のレコードを登録しました。」と表示させたいです。 プログラム package ex; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.SQLException; public class Insert { public static void main(String[] args) { String url = "jdbc:mysql://localhost:3306/sampledb"; /* データベースのユーザとパスワード */ String user = "????"; String password = "???"; String sql = "INSERT INTO m_employee(code,name,age,section) VALUES(?,?,?,?)"; try (Connection con = DriverManager.getConnection(url, user, password); PreparedStatement pstmt = con.prepareStatement(sql)){ pstmt.setString(1, args[0]); pstmt.setString(2, args[1]); pstmt.setString(3, args[2]); pstmt.setString(4, args[3]); int count = pstmt.executeUpdate(sql); System.out.println( count + "件のレコードを登録しました。"); } catch (SQLException e) { System.out.println("処理結果:異常が発生しました。"); e.printStackTrace(); } } } エラーコード 処理結果:異常が発生しました。 java.sql.SQLSyntaxErrorException: 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 '?,?,?,?)' at line 1 at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:120) at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122) at com.mysql.cj.jdbc.StatementImpl.executeUpdateInternal(StatementImpl.java:1337) at com.mysql.cj.jdbc.StatementImpl.executeLargeUpdate(StatementImpl.java:2112) at com.mysql.cj.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1247) at ex.Insert.main(Insert.java:29)
Java