Java Google App Engine and Google Cloud SQL running on local dev server

12,962

Solution 1

I had the same problem.

I solved it by dropping the mysql .jar in appengine-java-sdk-x.x.x/lib/impl.

Solution 2

Matt's answer helped me a lot, I believe this is a more complete explanation.

I can verify that you can get a local MYSQL instance to work with Google App Engine running in development mode, so as not to incur the upcoming costs associated with the Cloud SQL option from Google, while developing.

First, as Matt said you have to put the mysql-connector jar into the APPENGINE_HOME/lib/impl.

I am on windows. I did this by first finding where my SDK resides. In my project in eclipse in package explorer I right click on "App Engine SDK[App Engine - 1.6.4]", I select Properties from the drop down menu, and in the resulting pop up click the blue "Configure SDKs..." link.

This reveals the location of my App Engine SDK. Go to that folder in a Windows Explorer window, open lib/impl and drop in your mysql-connector jar, copied from your GAE eclipse project. My path was:

C:\Software\eclipse\plugins\com.google.appengine.eclipse.sdkbundle_1.6.4.v201203300216r37\appengine-java-sdk-1.6.4\lib\impl

Per the instructions here (https://developers.google.com/eclipse/docs/cloudsql-createapp) you are supposed to leave your java code connection string pointed at prod (jdbc:google:rdbms://... instead of jdbc:mysql://...) BUT you need to go into Eclipse project properties, Google, App Engine, Google Cloud SQL and under "Development SQL instance (used by local development server)" select the radio button "Use MySQL instance". Next time you launch GAE the connection string in your java code will be ignored in favor of your local MySQL host.

Make sure MySQL service is running and you are good to go.

This took me longer to figure out than it should have. I think the key is from the Google Docs, if you don't understand / use this information you will try and use a mysql jdbc string and run into socket permission errors because GAE can't go to port 3306 unless you do as I describe:

You do not need to explicitly connect to the Development SQL instance in your code - this is done for you automatically when you run your application in the development server. The development SQL instance to connect to is passed automatically to your development server via VM arguments by GPE at runtime.

(I uploaded 4 images to help with this explanation and only after I finished does it tell me you need 10 reputation points to load images--jeesh)

Solution 3

AFAIK If you are using GAE then you cannot use JDBC driver. I don't know how it could work in eclipse while Socet class is restricted in GAE. You should use internal GAE driver instead mysql JDBC.

com.google.appengine.api.rdbms.AppEngineDriver

Then, in eclipse you might configure connection to your local mysql db as in example see also this example how it is configured

Compiling as pure GWT and putting it into Tomcat with JDBC, should work, but not as a GAE application.

Solution 4

I just installed Eclipse + GPE4.2 in a new machine using GAE SDK1.7.5 on Juno Service Release 1 Build id: 20121004-1855 and was forced to copy the JDBC driver at appengine-java-sdk-x.x.x/lib/impl. Initially I had forgotten about this and I spent about 2 days debugging my code.

It would be nice if there was more information available on GPE page issues. It would be nice to be able to Google more information.

Share:
12,962
Ben B
Author by

Ben B

Studying Comp Sci at RMIT

Updated on June 06, 2022

Comments

  • Ben B
    Ben B about 2 years

    I've been researching a solution to this all week and while there have been solutions to similar problems there are none that address and rectify this problem directly.

    I have created a web application project using Google App Engine and Google Cloud SQL. Running the GAE application using the eclipse Google plugin and a local MySQL server the application works great.

    When running the application from the command line using:-

    sudo /opt/appengine-java-sdk-1.6.1/bin/dev_appserver.sh --jvm_flag=-Drdbms.server=local --jvm_flag=-Drdbms.driver=com.mysql.jdbc.Driver --jvm_flag=-Drdbms.url=jdbc:mysql://localhost:3306/twincam?user=root --port=7070 /home/ben/workspace/Twincam/war
    

    I get the following:-

    java.lang.IllegalStateException: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
    at com.google.appengine.api.rdbms.dev.LocalRdbmsServiceLocalDriver.registerDriver(LocalRdbmsServiceLocalDriver.java:95)
    

    I have the classpath referencing the mysql-connector.jar located in /Twincam/war/WEB-INF/lib/mysql-connector-java-5.1.18-bin.jar referenced by my user library as in the following .classpath file and directory structure :-

       <?xml version="1.0" encoding="UTF-8"?>
    <classpath>
        <classpathentry kind="src" path="src"/>
        <classpathentry kind="con" path="com.google.appengine.eclipse.core.GAE_CONTAINER"/>
        <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
        <classpathentry kind="lib" path="war/WEB-INF/lib/mysql-connector-java-5.1.18-bin.jar"/>
        <classpathentry kind="lib" path="war/WEB-INF/lib/gson-2.1-javadoc.jar"/>
        <classpathentry kind="lib" path="war/WEB-INF/lib/gson-2.1-sources.jar"/>
        <classpathentry kind="lib" path="war/WEB-INF/lib/gson-2.1.jar"/>
        <classpathentry kind="output" path="war/WEB-INF/classes"/>
    </classpath>
    

    enter image description here

    Update: I checked file permissions and all are set at the default 664 so I'm confident that this is not the problem.

  • Ben B
    Ben B over 12 years
    Thanks for the reply but the first link explicitly supplies a link to donwload the JDBC Driver for use with eclipse. The VM arguments that I used are straight from here and also reference a package within mysql-connector-java-5.1.18-bin.jar
  • Funky coder
    Funky coder over 11 years
    Thanks for pointing out the thing about the URL. I think it is a bit unclear in the docs. For everybody who have spent some time figuring out why they recieve AccessRestrictedExceptions: DO NOT USE THE DIRECT URL TO MYSQL INSTANCE WHEN APPENGINE IS ENABLED. Use the standard "Google URL" such as jdbc:google:rdbms://instance_name/guestbook and the App engine will replace it on the fly
  • Alon Shmiel
    Alon Shmiel over 11 years
    @MattFenwick, where can I find the appengine-java-sdk-x.x.x/lib/impl? I use eclipse in windows..
  • Amir Uval
    Amir Uval over 11 years
    @AlonShmiel look in the eclipse properties > google > app engine > configure sdk
  • LostPuppy
    LostPuppy almost 11 years
    @mark scheel you are my hero of the day. I was breaking my head with this annoying bug and was helpless till i found you answer.
  • Jay
    Jay about 8 years
    Still having so much trouble with this. Can someone help me out? stackoverflow.com/questions/36257087/…