Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Class.forName("com.mysql.jdbc.Driver");
- Connection conn = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/mydb" +
- "?cachePrepStmts=true", "user", "pass");
- for (int i = 0; i < 5; i++) {
- PreparedStatement ps = conn.prepareStatement("select * from MYTABLE where id=?");
- ps.setInt(1, 1);
- ps.execute();
- }
- conn.close()
- Connection conn = DatabaseUtil.getConnection();
- PreparedStatement stmtUpdate = conn.prepareStatement("UPDATE foo SET bar=? WHERE id = ?);
- for(int id=0; id<10; id++){
- stmtUpdate.setString(1, "baz");
- stmtUpdate.setInt(2, id);
- int rows = stmtUpdate.executeUpdate();
- // Clear parameters for reusing the preparedStatement
- stmtUpdate.clearParameters();
- }
- conn.close();
Add Comment
Please, Sign In to add comment