Is read operations lack the table for write opeartions?

Discussions

General J2EE: Is read operations lack the table for write opeartions?

  1. Is read operations lack the table for write opeartions? (2 messages)

    Hi all,
     Am using Oracle8i as back-end for our project.
     Can a read opearation lock the table?
     Class A {
        B b;
        A() {
            b = new B();
        }
        methA() {
          Statement stmt = null;
          ResultSet rs = null;
          try{
           //get the connection
           Connection con = getConnection()//private fmethod that returns a connetion object
           //create statement
           stmt = con.createStatement();
           rs = stmt.exceuteQuery(some select statement);
           b.meth();
           }catch(Exception e) {
           }
           finally{
              rs.close();
              stmt.close();
           }
        }
     }

     class B {
       meth() {
          Statement stmt = null;
          ResultSet rs = null;
          try{
           //get the connection
           Connection con = getConnection()//private fmethod that returns a connetion object
           //create statement
           stmt = con.createStatement();
           rs = stmt.exceuteQuery(some select statement from the same table);
           b.meth();
           }catch(Exception e) {
           }
           finally{
              rs.close();
              stmt.close();
           }
        }

     }

     Am calling B's method without closing the result set opened in A.
     Will it cause the table locking. The two statements that am executing fetches the data from the same table.

     Is read operation lock the table for write opeartions?

    thanks in advance
    Anila
  2. Hi,
    Actually its not, but im not sure whether this is different between databases. I tested here with Microsoft Access database, there im able to retrieve and update at the same time.Nothing like table lock is happening here.

    Given below is my sample program which i tested here,

    ------------------------------------------------------------------------------

    import java.sql.*;

    class dbTest {
    public static void main(String[] args) {
    try {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    String url = "jdbc:odbc:test";
    Connection con = DriverManager.getConnection(url);
    Statement stmt = con.createStatement();
    ResultSet rs = stmt.executeQuery("SELECT Name FROM UserData");

    String s = "";
    while (rs.next()) {
    s = rs.getString("Name");
    System.out.println("Name:"+s);
    }

    rs = stmt.executeQuery("select ID1 from UserData");
    while(rs.next()) {
    System.out.println("id >> "+rs.getString("ID1"));
    }

    String insQuery = "insert into UserData(Name) values('binish')";
    stmt = con.createStatement();

    int i = stmt.executeUpdate(insQuery);
    System.out.println(i);

    stmt.close();
    rs.close();
    con.close();
    }catch(Exception e) {
    System.out.println(e.toString());
    }
    }
    }
    ------------------------------------------------------------------------------

    Hope u got the idea, any queries revert back to me.

    Regards
    Arun (NArunpra at chn dot cognizant dot com)
  3. Read operation does not locks table unless you have changes the isolation level of your database. Infact in Oracle there is row level locking rather than table level.
    If your database has repeatable read isolation level then it may lock that particular record.