Reputation: 1860
I am trying to connect from my java app running on a Google Cloud Run instance, to a Google Cloud Sql instance that is part of the same Google Cloud project.
When my app tries to open a connection to the db, it throws the following error...
org.jdbi.v3.core.ConnectionException: java.sql.SQLException: Cannot create JDBC driver of class '' for connect URL 'jdbc:google:mysql://my-gc-app:my-cloud-sql-instance/mydb'
I have enabled all the correct roles for the cloud run service to connect to the cloud sql instance.
The java code that is establishing the DataSource is as follows...
BasicDataSource dataSource = new BasicDataSource();
dataSource.setUrl("jdbc:google:mysql://my-gc-app:my-cloud-sql-instance/mydb");
dataSource.setUsername(mySqlUser);
dataSource.setPassword(mySqlusersPassword);
dataSource.setMinIdle(5);
dataSource.setMaxIdle(10);
dataSource.setMaxOpenPreparedStatements(100);
Database.instantiate(dataSource);
Upvotes: 0
Views: 766
Reputation: 142
You're missing a line that specifies which DB type should be used. For example if you're going to connect to Mysql server.
dataSource.setDriverClassName("com.mysql.jdbc.Driver");
If it leads to a driver not found error or sth like that, try adding the library with the keyword mysql:mysql-connector-java:8.0.12
Upvotes: 2