File tree Expand file tree Collapse file tree 2 files changed +18
-3
lines changed
online-store.persistence/src/main/java/com/itbulls/learnit/onlinestore/persistence/utils Expand file tree Collapse file tree 2 files changed +18
-3
lines changed Original file line number Diff line number Diff line change 44import java .sql .DriverManager ;
55import java .sql .SQLException ;
66
7+ import com .itbulls .learnit .onlinestore .persistence .utils .connectionpools .DbcpDemo ;
8+
79public 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 }
Original file line number Diff line number Diff 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" );
You can’t perform that action at this time.
0 commit comments