Skip to content
Snippets Groups Projects
Commit a2c0b401 authored by Addin Munawwar's avatar Addin Munawwar
Browse files

feat: init util classes

parent 94a2fe6c
No related merge requests found
package com.soap.util;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import io.github.cdimascio.dotenv.Dotenv;
public class DbUtils {
private static Connection conn = createConnection();
public static Connection getConnection() {
if (conn == null) {
conn = createConnection();
}
return conn;
}
private static Connection createConnection() {
Dotenv dotenv = Dotenv.load();
String url = dotenv.get("DATABASE_URL");
String user = dotenv.get("MYSQL_USER");
String password = dotenv.get("MYSQL_PASSWORD");
try {
return DriverManager.getConnection(url, user, password);
} catch (SQLException e) {
System.out.println("Error creating connection");
throw new RuntimeException(e);
}
}
public static void closeConnection() {
try {
if (conn != null && !conn.isClosed()) {
conn.close();
}
} catch (SQLException e) {
System.out.println("Error closing connection");
throw new RuntimeException(e);
}
}
}
package com.soap.util;
public class EmailUtils {
}
package com.soap.util;
public class LoggingUtils {
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment