如何在Java JDBC程序中使用INSERT SQL语句?

时间:2015-10-06 16:24:18

标签: java jdbc

我有以下代码:

                try{    

                        String select2 =   "INSERT INTO employees VALUES (17, 'Adam', 'Kizzam', 'aa@zz.com', '123-456-7890', '12-DEC-00', '1234', '12345.23, 50', '12.25', 1222, 4769 ) ";

                        PreparedStatement preparedStatement2 = connection.prepareStatement(select2); // dbConnection. prepareStatement(selectSQL);
                        ResultSet rs2 = preparedStatement2.executeUpdate(select2);

                        while (rs.next()) {
                          String userid = rs.getString("EMPLOYEE_ID");
                          String username = rs.getString("FIRST_NAME");
                          System.out.println ("the userid , username are " + userid + " " +  username);
                } }

这给了我以下错误:

  

错误(54,77):不兼容的类型; required:java.sql.ResultSet;   发现:
  int DBConnection.java C:\ JDeveloper \ mywork \ OracleDatabaseApp \ OracleDatabaseApp \ src \ oracledatabaseapp OracleDatabaseApp.jpr

1 个答案:

答案 0 :(得分:4)

executeUpdate返回一个int

int rows = preparedStatement2.executeUpdate(select2);