import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; public class UpdateExample { public static void main(String[] args) { try { Class.forName("oracle.jdbc.driver.OracleDriver"); Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "system", "pragna"); String updateQuery = "UPDATE emp SET ESAL = ? WHERE EID = ?"; PreparedStatement pstmt = con.prepareStatement(updateQuery); pstmt.setInt(1, 60000); // New ESAL pstmt.setInt(2, 30); // EID of the employee to update int rowsUpdated = pstmt.executeUpdate(); System.out.println("Rows updated: " + rowsUpdated); pstmt.close(); con.close(); } catch (Exception e) { e.printStackTrace(); } } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter