test
Форк от lirfrnk/test
1package com.bittercode.util;
2
3import java.sql.Connection;
4import java.sql.DriverManager;
5import java.sql.SQLException;
6
7import com.bittercode.constant.ResponseCode;
8import com.bittercode.model.StoreException;
9
10public class DBUtil {
11
12private static Connection connection;
13
14static {
15
16try {
17
18Class.forName(DatabaseConfig.DRIVER_NAME);
19
20connection = DriverManager.getConnection(DatabaseConfig.CONNECTION_STRING, DatabaseConfig.DB_USER_NAME,
21DatabaseConfig.DB_PASSWORD);
22} catch (SQLException | ClassNotFoundException e) {
23
24e.printStackTrace();
25
26}
27
28}// End of static block
29
30public static Connection getConnection() throws StoreException {
31
32if (connection == null) {
33throw new StoreException(ResponseCode.DATABASE_CONNECTION_FAILURE);
34}
35
36return connection;
37}
38
39}
40