diff --git a/jdbc-transaction/src/main/java/dev/struchkov/example/transaction/Repository.java b/jdbc-transaction/src/main/java/dev/struchkov/example/transaction/Repository.java
index 3ddf9ee..287b8e2 100644
--- a/jdbc-transaction/src/main/java/dev/struchkov/example/transaction/Repository.java
+++ b/jdbc-transaction/src/main/java/dev/struchkov/example/transaction/Repository.java
@@ -24,4 +24,16 @@ public final class Repository {
return null;
}
+ public static Connection getConnectionH2() {
+ try {
+ final String url = "jdbc:h2:file:/Users/upagge/IdeaProjects/struchkov/example/spring-boot/spring-boot-transaction/db/test";
+ final String user = "sa";
+ final String passwd = "pass";
+ return DriverManager.getConnection(url, user, passwd);
+ } catch (SQLException e) {
+ log.error(e.getMessage(), e);
+ }
+ return null;
+ }
+
}
diff --git a/jdbc-transaction/src/main/java/dev/struchkov/example/transaction/problems/DirtyReadExample.java b/jdbc-transaction/src/main/java/dev/struchkov/example/transaction/problems/DirtyReadExample.java
index b062485..ebc2863 100644
--- a/jdbc-transaction/src/main/java/dev/struchkov/example/transaction/problems/DirtyReadExample.java
+++ b/jdbc-transaction/src/main/java/dev/struchkov/example/transaction/problems/DirtyReadExample.java
@@ -11,13 +11,13 @@ public class DirtyReadExample {
public static void main(String[] args) throws SQLException, InterruptedException {
try (
- final Connection connection = Repository.getConnection();
+ final Connection connection = Repository.getConnectionH2();
final Statement statement = connection.createStatement()
) {
connection.setAutoCommit(false);
connection.setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
- statement.execute("UPDATE person SET balance = 100000 WHERE id = 1");
+ statement.executeUpdate("UPDATE person SET balance = 100000 WHERE id = 1");
new OtherTransaction().start();
Thread.sleep(2000);
@@ -30,7 +30,7 @@ public class DirtyReadExample {
@Override
public void run() {
try (
- final Connection connection = Repository.getConnection();
+ final Connection connection = Repository.getConnectionH2();
final Statement statement = connection.createStatement()
) {
connection.setAutoCommit(false);
diff --git a/pom.xml b/pom.xml
index 091add6..ecfbf5d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -39,5 +39,10 @@
slf4j-api
1.7.36
+
+ com.h2database
+ h2
+ 2.1.214
+