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 Original file line number Diff line number Diff line change 4
4
import java .sql .DriverManager ;
5
5
import java .sql .SQLException ;
6
6
7
+ import com .itbulls .learnit .onlinestore .persistence .utils .connectionpools .DbcpDemo ;
8
+
7
9
public class DBUtils {
8
10
9
11
private static final String JDBC_MYSQL_HOST = "jdbc:mysql://localhost:3306/" ;
@@ -15,10 +17,18 @@ private DBUtils() {
15
17
}
16
18
17
19
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
+
18
29
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 ) {
22
32
throw new RuntimeException (e );
23
33
}
24
34
}
Original file line number Diff line number Diff line change @@ -10,6 +10,11 @@ public class DbcpDemo {
10
10
private static BasicDataSource ds = new BasicDataSource ();
11
11
12
12
static {
13
+ try {
14
+ Class .forName ("com.mysql.cj.jdbc.Driver" );
15
+ } catch (ClassNotFoundException e ) {
16
+ throw new RuntimeException (e );
17
+ }
13
18
ds .setUrl ("jdbc:mysql://localhost:3306/learn_it_db" );
14
19
ds .setUsername ("root" );
15
20
ds .setPassword ("root" );
You can’t perform that action at this time.
0 commit comments