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
-
Is read operations lack the table for write opeartions? (2 messages)
- Posted by: anila G
- Posted on: November 11 2003 06:15 EST
Threaded Messages (2)
- Is read operations lack the table for write opeartions? by Arun Prasad N on November 11 2003 09:21 EST
- Is read operations lack the table for write opeartions? by Badrish Agarwal on November 12 2003 05:16 EST
-
Is read operations lack the table for write opeartions?[ Go to top ]
- Posted by: Arun Prasad N
- Posted on: November 11 2003 09:21 EST
- in response to anila G
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) -
Is read operations lack the table for write opeartions?[ Go to top ]
- Posted by: Badrish Agarwal
- Posted on: November 12 2003 05:16 EST
- in response to anila G
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.