Friday, 3 June 2011

Write a java program which illustrates the concept of updatable ResultSet?

Write a java program which illustrates the concept of updatable ResultSet?
import java.sql.*;
class UpdateResultSet {
 public static void main(String[] args) {
   try {
    Class.forName("Sun.jdbc.odbc.JdbcOdbcDriver");
    System.out.println("DRIVERS LOADED...");
    Connection con = DriverManager.getConnection("jdbc:odbc:oradsn", "scott", "tiger");
    System.out.println("CONNECTION ESTABLISHED...");
    Statement st = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
    ResultSet rs = st.executeQuery("select * from emp1");
    rs.next();
    rs.updateInt(2, 8000);
    rs.updateRow();
    System.out.println("1 ROW UPDATED...");
    rs.moveToInsertRow();
    rs.updateInt(1, 104);
    rs.updateInt(2, 2000);
    rs.insertRow();
    System.out.println("1 ROW INSERTED...");
    rs.absolute(2);
    rs.deleteRow();
    System.out.println("1 ROW DELETED...");
    con.close();
   } catch (Exception e) {
    e.printStackTrace();
   }
  } // main
}   // UpdateResultSet

Write a java program which illustrates the concept of Batch processing?

Write a java program which illustrates the concept of Batch processing?
import java.sql.*;
class BatchProConcept {
 public static void main(String[] args) throws Exception {
   Class.forName("Sun.jdbc.odbc.JdbcOdbcDriver");
   System.out.println("DRIVERS LOADED...");
   Connection con = DriverManager.getConnection("jdbc:odbc:oradsn", "scott", "tiger");
   System.out.println("CONNECTION ESTABLISHED...");
   con.setAutoCommit(false);
   Statement st = con.createStatement();
   st.addBatch("insert into student values (3, 'j2ee')");
   st.addBatch("delete from student where sno=1");
   st.addBatch("update student set sname='java' where sno=2");
   int res[] = st.executeBatch();
   for (int i = 0; i < res.length; i++) {
    System.out.println("NUMBER OF ROWS EFFECTED : " + res[i]);
   }
   con.commit();
   con.rollback();
   con.close();
  } // main
}   // BatchProConcept

Write a java program to create a table through frontend application?

Write a java program to create a table through frontend application?
import java.sql.*;
class CreateTable {
 public static void main(String[] args) {
   try {
    Class.forName("Sun.jdbc.odbc.JdbcOdbcDriver");
    System.out.println("DRIVERS LOADED...");
    Connection con = DriverManager.getConnection("jdbc:odbc:oradsn", "scott", "tiger");
    System.out.println("CONNECTION ESTABLISHED...");
    Statement st = con.createStatement();
    int i = st.executeUpdate("create table kalyan (eno number (4), ename varchar2 (15))");
    System.out.println("TABLE CREATED...");
    con.close();
   } catch (Exception e) {
    e.printStackTrace();
   }
  } // main
}  // CreateTable