Skip to content

Commit 8ac6d7e

Browse files
committed
update: enhance MySQL database initialization with driver loading and URL validation
1 parent 6ea5817 commit 8ac6d7e

1 file changed

Lines changed: 10 additions & 8 deletions

File tree

src/main/java/me/axeno/hommr/managers/DatabaseManager.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,20 @@ public class DatabaseManager {
2121
private Dao<Home, Integer> homeDao;
2222

2323
public void init(String dbUrl, String dbUser, String dbPassword) {
24-
try {
25-
Class.forName("com.mysql.cj.jdbc.Driver");
26-
} catch (ClassNotFoundException e) {
27-
Hommr.getInstance().getSLF4JLogger().error("MySQL database driver not found. Please ensure the MySQL driver is included in the classpath.");
28-
throw new RuntimeException(e);
24+
if (dbUrl == null || dbUrl.isEmpty()) {
25+
throw new IllegalStateException("Database URL is not configured. Please set 'database.connection.url' in config.yml");
2926
}
3027

31-
try {
32-
if (dbUrl == null || dbUrl.isEmpty()) {
33-
throw new IllegalStateException("Database URL is not configured. Please set 'database.connection.url' in config.yml");
28+
if (dbUrl.startsWith("jbdc:mysql:")) {
29+
try {
30+
Class.forName("com.mysql.cj.jdbc.Driver");
31+
} catch (ClassNotFoundException e) {
32+
Hommr.getInstance().getSLF4JLogger().error("MySQL database driver not found. Please ensure the MySQL driver is included in the classpath.");
33+
throw new RuntimeException(e);
3434
}
35+
}
3536

37+
try {
3638
connectionSource = new JdbcPooledConnectionSource(dbUrl, dbUser, dbPassword);
3739

3840
homeDao = DaoManager.createDao(connectionSource, Home.class);

0 commit comments

Comments
 (0)