Unable to connect database of lamp instance from servlet running on tomcat instance of google cloud

117 views Asked by At

I have two instances of my project running on Google's cloud, Tomcat Instance & Lamp Instance.

My servlets are running on tomcat instance and have to connect to the database of lamp instance.

I gave the following details of connection

String DriverName="com.mysql.jdbc.Driver";
String userName="root";
String password="root";
String driverManager="jdbc:mysql://localhost:3306/databasename";

The localhost request is going to mysql of tomcat instance(Here tomcat instance contains mysql also).It is not going to the lamp instance

So I want a way to send request to another instance.

if I placed lamp instance url means i am receiving the following exception in the logcat.

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

So can anyone tell how to solve this problem

thanks in advance.

1

There are 1 answers

1
K139 On

You need to enable the Connector/J by setting it to true, and also use the google mysql driver instead of the generic com.mysql.jdbc.Driver class.

Enable connector/j

<?xml version="1.0" encoding="utf-8"?>
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
  ...
  <use-google-connector-j>true</use-google-connector-j>
</appengine-web-app>

Google Driver class

Class.forName("com.mysql.jdbc.GoogleDriver");

Code samples taken from URL.