0

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?

JSmith
  • 4,519
  • 4
  • 29
  • 45
  • @Shadow not sure why this should be marked as duplicate as answers on the post are mostly for local databases and imply user have access to the database settings – JSmith Jan 03 '19 at 00:28
  • 1
    You are unlikely to fix this problem if you do not have access to configure your mysql database. Perhaps you should not use a free mysql service. The linked topic and the duplicate linked there sum up what could have gone wrong if you get this error message. – Shadow Jan 03 '19 at 00:32
  • okay thank you @Shadow. – JSmith Jan 03 '19 at 00:32
  • @Shadow well that wasn't the problem. Problem was I needed to activate billing service for my project. – JSmith Jan 03 '19 at 02:07

0 Answers0