Advertisement
attila66

ResultSet insert new record

May 11th, 2020
3,146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.87 KB | None | 0 0
  1.     public int test(int pId, String pName, String pCity, int pSalary) {
  2.         int retVal = 1;
  3.         String connURL = "jdbc:mysql://localhost:3306/test";
  4.         String query = "SELECT * FROM person LIMIT 1";
  5.         try (Connection conn = DriverManager.getConnection(connURL,"***", "***");
  6.              PreparedStatement pstmt = conn.prepareStatement(
  7.                 query,
  8.                 ResultSet.TYPE_FORWARD_ONLY,
  9.                 ResultSet.CONCUR_UPDATABLE);
  10.              ResultSet res = pstmt.executeQuery() )
  11.         {
  12.             res.moveToInsertRow();
  13.             res.updateInt("id", pId);
  14.             res.updateString("name", pName);
  15.             res.updateString("city", pCity);
  16.             res.updateInt("salary", pSalary);
  17.             res.insertRow();
  18.  
  19.         } catch (SQLException ex) {
  20.             retVal = 0;
  21.         }
  22.         return retVal;
  23.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement