Skip to content

Commit b5bd84d

Browse files
Connection Pool Homework
1 parent e5c785d commit b5bd84d

File tree

2 files changed

+18
-3
lines changed
  • online-store.persistence/src/main/java/com/itbulls/learnit/onlinestore/persistence/utils

2 files changed

+18
-3
lines changed

Diff for: online-store.persistence/src/main/java/com/itbulls/learnit/onlinestore/persistence/utils/DBUtils.java

+13-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import java.sql.DriverManager;
55
import java.sql.SQLException;
66

7+
import com.itbulls.learnit.onlinestore.persistence.utils.connectionpools.DbcpDemo;
8+
79
public class DBUtils {
810

911
private static final String JDBC_MYSQL_HOST = "jdbc:mysql://localhost:3306/";
@@ -15,10 +17,18 @@ private DBUtils() {
1517
}
1618

1719
public static Connection getConnection() {
20+
// Commented during the implementation of the Connection Pool Homework - TODO - remove this code in final solution
21+
// try {
22+
// Class.forName("com.mysql.cj.jdbc.Driver");
23+
// return DriverManager.getConnection(JDBC_MYSQL_HOST + DB_NAME, USERNAME, PASSWORD);
24+
// } catch (SQLException | ClassNotFoundException e) {
25+
// throw new RuntimeException(e);
26+
// }
27+
28+
1829
try {
19-
Class.forName("com.mysql.cj.jdbc.Driver");
20-
return DriverManager.getConnection(JDBC_MYSQL_HOST + DB_NAME, USERNAME, PASSWORD);
21-
} catch (SQLException | ClassNotFoundException e) {
30+
return DbcpDemo.getConnection();
31+
} catch (SQLException e) {
2232
throw new RuntimeException(e);
2333
}
2434
}

Diff for: online-store.persistence/src/main/java/com/itbulls/learnit/onlinestore/persistence/utils/connectionpools/DbcpDemo.java

+5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ public class DbcpDemo {
1010
private static BasicDataSource ds = new BasicDataSource();
1111

1212
static {
13+
try {
14+
Class.forName("com.mysql.cj.jdbc.Driver");
15+
} catch (ClassNotFoundException e) {
16+
throw new RuntimeException(e);
17+
}
1318
ds.setUrl("jdbc:mysql://localhost:3306/learn_it_db");
1419
ds.setUsername("root");
1520
ds.setPassword("root");

0 commit comments

Comments
 (0)