2
votes

My GWT application does not seem to find mysql-connector-java-5.1.22-bin.jar. Im using the Google App Engine.

I have set the jar in Project->RIghtClick->Properties->Java Build Path->Libraries->mysql-connector-java-5.1.22-bin.jar. I also added the "MySQL JDBC Driver". The $CLASSPATH is set correctly too (i dont think it matters because Im running the application in Eclipse).

I have tested the same code on command line and it works like a charm.

$ java -cp ~/mysql-connector-java-5.1.22/mysql-connector-java-5.1.22-bin.jar:. JDBCExample
-------- MySQL JDBC Connection Testing ------------
MySQL JDBC Driver Registered!
You made it, take control your database now!

When I run the Web Application in Eclipse, I get this

Exception:

-------- MySQL JDBC Connection Testing ------------
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
ClassNotFound - Where is your MySQL JDBC Driver?com.mysql.jdbc.Driver
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
    at com.google.appengine.tools.development.IsolatedAppClassLoader.loadClass(IsolatedAppClassLoader.java:207)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:186)
    at com.startupweekend.server.GreetingServiceImpl.readDB(GreetingServiceImpl.java:65)
    at com.startupweekend.server.GreetingServiceImpl.greetServer(GreetingServiceImpl.java:21)

Code:

try {
  Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e) {
  System.out.println("ClassNotFound - Where is your MySQL JDBC Driver?" + e.getMessage());              
  e.printStackTrace(); 
  return;
} 
2

2 Answers

4
votes

I'm not completely sure, but you should just put the mysql driver in your WEB-INF/lib folder and then right click -> add to build path. That should make it work.

Bear in mind that in GAE you cannot use common relational databases, you can only use Google CloudSQL.

0
votes

You don't need the App Engine, just use GWT compile when you're ready for your war file. In any case, right click project folder -> properties -> Google -> App Engine -> uncheck 'Use Google App Engine'. Make sure the mysql-connector is in your lib folder. Enjoy your favorite relational database, and more.

Cheers