Tuesday, February 28, 2012

Loading mysql JDBC jar file -

I'm running my app locally, to test out connection to my new CloudSQL
Instance.

I'm loading the JDBC Driver in my code:
DriverManager.registerDriver(new AppEngineDriver());
Connection c = DriverManager
.getConnection("jdbc:google:rdbms://<projectName>:<InstanceName>/
<DBName>");

On executing locally, I get this error:

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
Caused by:
java.lang.IllegalStateException: java.lang.ClassNotFoundException:
com.mysql.jdbc.Driver

On forums, I read this:
"Google App Engine doesn't allow you to open Sockets. When you try to
load the JDBC driver, it makes a socket connection in a static block.
An exception in the static block leads to a ClassNotFoundException,
which is what you are seeing..."

Mysql-connector-java-5.1.18-bin.jar is in my Eclipse Build path.

What is the workaround to the Sockets issue in GAE?

In this appengine how-to section for cloudSQL, I don't find any
special reference to taking care of this situation:
https://developers.google.com/cloud-sql/docs/developers_guide_java#register_the_driver

Any pointers greatly appreciated!

Thanks,
-Shiv

No comments:

Post a Comment