简体   繁体   中英

How do you use the INSERT SQL statement in a Java JDBC program?

I have the following code :

                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);
                } }

This gives me the following error :

Error(54,77): incompatible types; required: java.sql.ResultSet; found:
int DBConnection.java C:\\JDeveloper\\mywork\\OracleDatabaseApp\\OracleDatabaseApp\\src\\oracledatabaseapp OracleDatabaseApp.jpr

executeUpdate返回一个 int

int rows = preparedStatement2.executeUpdate(select2);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM