Advertisement
SVXX

JDBC Update using PrepStatement

Sep 1st, 2013
371
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.86 KB | None | 0 0
  1. package college;
  2. import java.sql.*;
  3.  
  4. public class Update {
  5.      public static void main(String[] args) {
  6.     Connection con;
  7.         PreparedStatement pstmt;
  8.         try
  9.         {
  10.             Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  11.             con=DriverManager.getConnection("Jdbc:Odbc:Aakarshap");
  12.             con.setAutoCommit(false); //Set this silly property to false
  13.           String qrystr="Update Employee set Salary=Salary+1000 where eNum=?";
  14.             pstmt=con.prepareStatement(qrystr);
  15.             pstmt.setInt(1, 1001);
  16.             pstmt.executeUpdate();
  17.             con.commit(); //Manually commit like a God
  18.         }
  19.         catch(ClassNotFoundException ce)
  20.         {
  21.             System.out.println("Error"+ce);
  22.         }
  23.         catch(SQLException se)
  24.         {
  25.             System.out.println("Error"+se);
  26.         }
  27.      }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement