Skip to content

Commit 089871a

Browse files
imjalpreettdcmeehan
authored andcommitted
Resolve "No suitable driver found" error in DB-based SPM
Fixes the runtime error: Caused by: ConnectionException: SQLException: No suitable driver found for jdbc:mysql://... The issue occurs when both MariaDB and MySQL JDBC drivers are present on the classpath, causing conflicts in driver resolution. This fix ensures the correct driver is selected at runtime.
1 parent 850cc31 commit 089871a

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

presto-db-session-property-manager/src/main/java/com/facebook/presto/session/db/DbSessionPropertyManagerConfig.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
public class DbSessionPropertyManagerConfig
2424
{
2525
private String configDbUrl;
26+
private String jdbcDriverName = "com.mysql.jdbc.Driver";
2627
private Duration specsRefreshPeriod = new Duration(10, SECONDS);
2728

2829
@NotNull
@@ -38,6 +39,19 @@ public DbSessionPropertyManagerConfig setConfigDbUrl(String configDbUrl)
3839
return this;
3940
}
4041

42+
@NotNull
43+
public String getJdbcDriverName()
44+
{
45+
return jdbcDriverName;
46+
}
47+
48+
@Config("session-property-manager.db.driver-name")
49+
public DbSessionPropertyManagerConfig setJdbcDriverName(String jdbcDriverName)
50+
{
51+
this.jdbcDriverName = jdbcDriverName;
52+
return this;
53+
}
54+
4155
@NotNull
4256
@MinDuration("1ms")
4357
public Duration getSpecsRefreshPeriod()

presto-db-session-property-manager/src/main/java/com/facebook/presto/session/db/SessionPropertiesDaoProvider.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ public SessionPropertiesDaoProvider(DbSessionPropertyManagerConfig config)
3333
{
3434
requireNonNull(config, "config is null");
3535
requireNonNull(config.getConfigDbUrl(), "db url is null");
36+
37+
try {
38+
Class.forName(config.getJdbcDriverName());
39+
}
40+
catch (ClassNotFoundException e) {
41+
throw new RuntimeException("JDBC driver class not found: " + config.getJdbcDriverName(), e);
42+
}
43+
3644
this.dao = Jdbi.create(() -> DriverManager.getConnection(config.getConfigDbUrl()))
3745
.installPlugin(new SqlObjectPlugin())
3846
.onDemand(SessionPropertiesDao.class);

presto-db-session-property-manager/src/test/java/com/facebook/presto/session/db/TestDbSessionPropertyManagerConfig.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public void testDefaults()
3232
{
3333
assertRecordedDefaults(recordDefaults(DbSessionPropertyManagerConfig.class)
3434
.setConfigDbUrl(null)
35+
.setJdbcDriverName("com.mysql.jdbc.Driver")
3536
.setSpecsRefreshPeriod(new Duration(10, SECONDS)));
3637
}
3738

@@ -40,11 +41,13 @@ public void testExplicitPropertyMappings()
4041
{
4142
Map<String, String> properties = new ImmutableMap.Builder<String, String>()
4243
.put("session-property-manager.db.url", "foo")
44+
.put("session-property-manager.db.driver-name", "org.mariadb.jdbc.Driver")
4345
.put("session-property-manager.db.refresh-period", "50s")
4446
.build();
4547

4648
DbSessionPropertyManagerConfig expected = new DbSessionPropertyManagerConfig()
4749
.setConfigDbUrl("foo")
50+
.setJdbcDriverName("org.mariadb.jdbc.Driver")
4851
.setSpecsRefreshPeriod(new Duration(50, TimeUnit.SECONDS));
4952

5053
assertFullMapping(properties, expected);

0 commit comments

Comments
 (0)