Subject | Transaction and concurrent updates |
---|---|
Author | Miroslav Novak |
Post date | 2004-03-21T08:19:32Z |
Hi,
I have problem using transaction with JayBird for 1.5-beta-3-jdk14.
FireBird version is 1.5 for Windows. There are two connections in the
example, where one perfroms a select and then an update. The second one
updates the table between the select and update of the first connection. I
think such a code should cause deadlock exception, but it succeeds. Please
can you help me?
Mirek.
Database is called "piskovna" has a nonempty table "vozidla" with field
"spz". Here is the code I don't understand:
import java.sql.*;
public class TestTransact {
static String databaseUrl = "jdbc:firebirdsql://127.0.0.1/piskovna";
static void init() {
try {
Class.forName("org.firebirdsql.jdbc.FBDriver");
Connection conn1 =
DriverManager.getConnection(databaseUrl, "SYSDBA", "masterkey");
Connection conn2 =
DriverManager.getConnection(databaseUrl, "SYSDBA", "masterkey");
Statement stmt1 = conn1.createStatement();
Statement stmt2 = conn2.createStatement();
conn1.setAutoCommit(false);
conn2.setAutoCommit(false);
// select from the first connection
ResultSet rs = stmt1.executeQuery("select * from
vozidla;");
while (rs.next());
// change something from the second connection
stmt2.execute("update vozidla set spz='sss';");
conn2.commit();
// change something from the first connection
// this should fail, but it succeeds
stmt1.execute("update vozidla set spz='zzz';");
conn1.commit();
stmt1.close();
stmt2.close();
conn1.close();
conn2.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
public static void main(String[] args) {
init();
}
}
I have problem using transaction with JayBird for 1.5-beta-3-jdk14.
FireBird version is 1.5 for Windows. There are two connections in the
example, where one perfroms a select and then an update. The second one
updates the table between the select and update of the first connection. I
think such a code should cause deadlock exception, but it succeeds. Please
can you help me?
Mirek.
Database is called "piskovna" has a nonempty table "vozidla" with field
"spz". Here is the code I don't understand:
import java.sql.*;
public class TestTransact {
static String databaseUrl = "jdbc:firebirdsql://127.0.0.1/piskovna";
static void init() {
try {
Class.forName("org.firebirdsql.jdbc.FBDriver");
Connection conn1 =
DriverManager.getConnection(databaseUrl, "SYSDBA", "masterkey");
Connection conn2 =
DriverManager.getConnection(databaseUrl, "SYSDBA", "masterkey");
Statement stmt1 = conn1.createStatement();
Statement stmt2 = conn2.createStatement();
conn1.setAutoCommit(false);
conn2.setAutoCommit(false);
// select from the first connection
ResultSet rs = stmt1.executeQuery("select * from
vozidla;");
while (rs.next());
// change something from the second connection
stmt2.execute("update vozidla set spz='sss';");
conn2.commit();
// change something from the first connection
// this should fail, but it succeeds
stmt1.execute("update vozidla set spz='zzz';");
conn1.commit();
stmt1.close();
stmt2.close();
conn1.close();
conn2.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
public static void main(String[] args) {
init();
}
}