2

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;
} 
Thomas Broyer
  • 64,353
  • 7
  • 91
  • 164
Nikhil Joshi
  • 21
  • 1
  • 2

2 Answers2

4

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.

fernandohur
  • 7,014
  • 11
  • 48
  • 86
  • >> Bear in mind that in GAE you cannot use common relational databases, you can only use Google CloudSQL. Hi Woojah, I don't quite understand what that means. Can you please help elaborate. Project Projecties -> Google -> App Engine -> 'Use Google App Engine' is Checked. 'Enable Google Cloud SQL' is Unchecked. Is that incorrect? I am running everything locally…my URL is like this http://127.0.0.1:8888/TestApp.html?gwt.codesvr=127.0.0.1:9997 – Nikhil Joshi Dec 04 '12 at 19:31
  • @NikhilJoshi, take a look at this: https://developers.google.com/cloud-sql/ and this http://stackoverflow.com/questions/1306279/pros-cons-of-google-app-engine – fernandohur Dec 05 '12 at 23:27
0

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