无法在Java中使用“ executeUpdate()”

时间:2019-04-20 18:20:55

标签: java sql execute

我正在制作一个GUI应用程序,它将输入数据插入JDBC,但是我不能在代码中使用executeUpdate。 例外:java.sql.SQLException: Method 'executeUpdate(String)' not allowed on prepared statement.

  private void btnsaveMouseClicked(java.awt.event.MouseEvent evt) {                                     

        try {
            btnsave.setText("Inserted!");
            Connection MyconObj=null;
            Statement MystateObj =null;
            String name = jname.getText().toString();
            String lastname = jlastname.getText().toString();
            MyconObj = DriverManager.getConnection("jdbc:derby://localhost:1527/students", "root", "root");
            String query = "INSERT INTO ROOT.INFORMATION "+ "(NAME, LASTNAME) " + "VALUES (?,?)";

            PreparedStatement ps = null;
            ps = MyconObj.prepareStatement(query);
            ps.setString(1, name);
            ps.setString(2, lastname);
            System.out.println("Code runned.");
            ps.executeUpdate(query);
        } catch (SQLException ex) {
            Logger.getLogger(main.class.getName()).log(Level.SEVERE, null, ex);
        }


    }          ```

0 个答案:

没有答案