I've just deployed my app on google app engine but my MYSQL connection is really inconsistent.
I use Heliohost as a free Mysql provider
in best cases I can sign in into my app (so mysql connection works fine here) but when I automatically get redirected to member page I load a bunch of products from my database and then I get:
Communications link failure The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
When I ran the app locally and connect to remote MYSQL it worked just fine.
I always close statements, results and connections even when I throw an error. I've added the port 3306 to my url without change.
here is a sample code:
private String user = "**";
private String password = **;
private String address = "ricky.heliohost.org";
private String db = **;
private String port = "3306";
private String instanceUrl = "jdbc:mysql://" + address + ":" + port;
private String dbUrl = instanceUrl + "/" + db;
public Connection getDbConnection() throws SQLException, InstantiationException, IllegalAccessException, ClassNotFoundException {
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection conn = DriverManager.getConnection(this.dbUrl, this.user, this.password);
return (conn);
}
public String getProducts() throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException{
JSONArray products = new JSONArray();
Connection conn = getDbConnection();
Statement stmt = conn.createStatement();
ResultSet res = stmt.executeQuery("SELECT p.id, name, value FROM products AS p, products_quantity AS pq WHERE p.id = pq.product_id");
while (res.next())
{
JSONObject product = new JSONObject();
product.put("pid", res.getInt(1));
product.put("product", res.getString(2));
product.put("quantity", res.getInt(3));
products = products.put(product);
}
res.close();
stmt.close();
conn.close();
return(products.toString());
}
EDIT
Now cannot even sign in once into my app. After chatting with heliohost they told me the problem may not come from them as connection worked fine when I was devellopping on localhost. Is Google app engine has any kind of restrictions or settings to allow to connect to an external service?