Monday, December 5, 2011

Re: Is is possible to access Google Cloud SQL while running locally?

Ok I solved that driver error but I'm back to familiar ones.
Here are the 3 scenarios I have:
1) In a simple java project I have this code:
public static void main(String[] args) {
System.out.println("1");
try {
Class.forName("com.mysql.jdbc.Driver");
Connection c = DriverManager.getConnection(MY LOCAL MYSQL
CONNECTION STRING);
PreparedStatement ps = c.prepareStatement("SELECT * FROM
SOME_TABLE");
ResultSet rs = ps.executeQuery();
.....
This works and returns the correct values in the connection set.
2) In my GAE project I have

Connection c = null;
try {
DriverManager.registerDriver(new AppEngineDriver());
c = DriverManager.getConnection(MY GOOGLE CLOUD SQL CXN STRING);
PreparedStatement ps = c.prepareStatement("SELECT * FROM
SOME_TABLE");
ResultSet rs = ps.executeQuery();
It hits the catch block with this error:
[ERROR] Error listing items: java.sql.SQLException: Table not found in
statement [SELECT * FROM SOME_TABLE]
3) In my GAE project I have another method:
Connection c = null;
try {
Class.forName("com.mysql.jdbc.Driver");
c = DriverManager.getConnection(MY LOCAL MYSQL CONNECTION STRING);
PreparedStatement ps = c.prepareStatement("SELECT * FROM
SOME_TABLE");
This one throws this exception
[ERROR] Error listing items:
com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException:
Could not create connection to database server.

I am at my wits end here. What is going on?

No comments:

Post a Comment