1

Hello I can't connect to my google cloud sql instance through eclipse(Neon) I tried both app engine sdk plugin 1.9.34 and 1.9.42 (google plugin 4.6)

Could not connect to Profile (projectID.GoogleCloudSQL.DevInstance).
Error creating SQL Model Connection connection to Profile(projectID.GoogleCloudSQL.DevInstance). (Error: com.mysql.jdbc.Driver)
 com.mysql.jdbc.Driver
 Error creating Google Cloud SQL Connection factory connection to Profile (ProjectId.GoogleCloudSQL.DevInstance). (Error: com.mysql.jdbc.Driver)
 com.mysql.jdbc.Driver

Ping Failed!

 java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.net.FactoryURLClassLoader.loadClass(URLClassLoader.java:814)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at org.eclipse.datatools.connectivity.drivers.jdbc.JDBCConnection.createConnection(JDBCConnection.java:327)
at org.eclipse.datatools.connectivity.DriverConnectionBase.internalCreateConnection(DriverConnectionBase.java:105)
at org.eclipse.datatools.connectivity.DriverConnectionBase.open(DriverConnectionBase.java:54)
at org.eclipse.datatools.connectivity.drivers.jdbc.JDBCConnection.open(JDBCConnection.java:96)
at com.google.appengine.eclipse.datatools.connection.GoogleSqlConnectionFactory.createConnection(GoogleSqlConnectionFactory.java:36)
at org.eclipse.datatools.connectivity.internal.ConnectionFactoryProvider.createConnection(ConnectionFactoryProvider.java:83)
at org.eclipse.datatools.connectivity.internal.ConnectionProfile.createConnection(ConnectionProfile.java:359)
at org.eclipse.datatools.connectivity.ui.PingJob.createTestConnection(PingJob.java:76)
at org.eclipse.datatools.connectivity.ui.PingJob.run(PingJob.java:59)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)
montatich
  • 199
  • 1
  • 2
  • 14
  • The error indicates that Eclipse cannot find the JAR containing the JDBC Driver for MySQL. I'm not an Eclipse user so I cannot tell you exactly how to 'install' the MySQL Driver, but it needs to be on the class path for Eclipse to find it. – DuncanKinnear Sep 21 '16 at 22:17
  • Yes I already included mysql-connector-java-5.1.39-bin in class path – montatich Sep 21 '16 at 22:23
  • Have you followed the steps [as per these instructions](http://www.javahelps.com/2015/08/add-mysql-jdbc-driver-to-eclipse.html)? – DuncanKinnear Sep 21 '16 at 22:32
  • yes I did, I think it's a bug related issue – montatich Sep 21 '16 at 22:54
  • Does this work at the command line? If not, it's unlikely to be a problem with Eclipse or the Google Plugin for Eclipse. If it does work at the command line, I'd check how the classpath there differs from Eclipse's. But I concur with other posters, that this stack trace strongly suggests the relevant class is not in your classpath. One thing to try is instantiating it directly in your code, just to make sure it's there. – Elliotte Rusty Harold Sep 22 '16 at 15:47
  • yes the connection works fine at the command line, and trust me it's in my classpath, but when you say instantiate it direct in the code, can explain more, an example please? – montatich Sep 22 '16 at 16:04

1 Answers1

0

As this question never received an answer I'll post one here.

Instantiating directly in your code means to do this:

Class.forName("com.mysql.jdbc.Driver");

This will try to load the class manually and run its static initializer. The message "java.lang.ClassNotFoundException: com.mysql.jdbc.Driver" means the class is not in your classpath, so if you get the same error, it means you have a missing JAR or it's not where it's supposed to be.

Since you mentioned using the Google Plugin for Eclipse I'll assume you're working with an App Engine project. For this type of project your JARs must be in WEB-INF/lib directory, so make sure the mysql-connector-java JAR is there.

Adam
  • 5,697
  • 1
  • 20
  • 52