Advertisement
SVXX

JDBC UpdateAndShow

Sep 1st, 2013
473
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.30 KB | None | 0 0
  1. import java.sql.*;
  2.  
  3. public class UpdateAndShow {
  4.      public static void main(String[] args) {
  5.     Connection con;
  6.         PreparedStatement pstmt;
  7.         try
  8.         {
  9.             Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  10.             con=DriverManager.getConnection("Jdbc:Odbc:Aakarshap");
  11.             con.setAutoCommit(false);
  12.           String qrystr="Update Employee set Salary=Salary+1000 where eNum=?";
  13.             pstmt=con.prepareStatement(qrystr);
  14.             pstmt.setInt(1, 1001);
  15.             pstmt.executeUpdate();
  16.             con.commit();
  17.             Statement s = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
  18.             s.execute("SELECT * FROM Employee");
  19.             ResultSet rs = s.getResultSet();
  20.             rs.afterLast(); //go to just after last row.
  21.             while(rs.previous())
  22.             {
  23.                 int i;
  24.                 for(i = 1; i <= rs.getMetaData().getColumnCount(); i++)
  25.                 {
  26.                     System.out.print(rs.getString(i) + " ");
  27.                 }
  28.                 System.out.println();
  29.             }
  30.            
  31.         }
  32.         catch(ClassNotFoundException ce)
  33.         {
  34.             System.out.println("Error"+ce);
  35.         }
  36.         catch(SQLException se)
  37.         {
  38.             System.out.println("Error"+se);
  39.         }
  40.      }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement