3

here i am trying to connect to multiple databases here is my code,this code works fine in local machine but when i upload it to online this is not working may i get any help thank you in advance.

package dbase.sqlcon;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class ConnectionHelper{
    private String url;
    private String restrnturl;
    private String prptyurl;
    private String user= "root";
    private String pass= "mysql";
    private String userRestaurent= "root";
    private String passRestaurent= "mysql";
    private String userProperty= "root";
    private String passProperty= "mysql";

    private ConnectionHelper() {
        try {
            Class.forName("com.mysql.jdbc.Driver");

            URLDecoder.decode(getClass().getClassLoader().getResource("flex/testdrive").toString(), "UTF-8");



            url = "jdbc:mysql://192.168.10.1:3306/desisquare";
            restrnturl="jdbc:mysql://192.168.10.1:3306/foodndine";
            prptyurl="jdbc:mysql://192.168.10.1:3306/postaproperty";

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static Connection getConnection() throws SQLException {
        if (instance == null) {
            instance = new ConnectionHelper();
        }
        return DriverManager.getConnection(instance.url, instance.user, instance.pass);
    }
    public static Connection getConnectionrestaurent() throws SQLException {
        if (instance == null) {
            instance = new ConnectionHelper();
        }
        return DriverManager.getConnection(instance.restrnturl, instance.userRestaurent, instance.passRestaurent);
    }
    public static Connection getConnectionproperty() throws SQLException {
        if (instance == null) {
            instance = new ConnectionHelper();
        }
        return DriverManager.getConnection(instance.prptyurl, instance.userProperty, instance.passProperty);
    }

}

when i asked my hosting provider what is the problem he has send me this which is very new to me

INFO | jvm 1 | 2014/04/18 06:23:03 | Exception is ;java.sql.SQLException: Access denied for user 'postaproperty'@'localhost' (using password: YES)
INFO | jvm 1 | 2014/04/18 06:23:03 | Exception is ;java.sql.SQLException: Access denied for user 'postaproperty'@'localhost' (using password: YES)
INFO | jvm 1 | 2014/04/18 06:23:03 | Exception is ;java.sql.SQLException: Access denied for user 'foodndine'@'localhost' (using password: YES)
3bu1
  • 977
  • 12
  • 30

1 Answers1

1

There are way too may things that may have gone wrong. But as you've mentioned that the problem happens once you try to access your db from outside than such exception messages could indicate that your database is not reachable due to:

-In my.cnf you should verify that --skip-networking is commented out:

[mysqld]
user            = mysql
pid-file        = /var/run/mysqld/mysqld.pid
socket          = /var/run/mysqld/mysqld.sock
port            = 3306
basedir         = /usr
datadir         = /var/lib/mysql
tmpdir          = /tmp
language        = /usr/share/mysql/English
bind-address    = 65.55.55.2
# skip-networking

That is your database is said to accept messages via TCP/IP

  • Verify that your database server is listening on 3306 port
  • Verify that 192.168.10.1 is reachable from your deployment site (telnet 192.168.10.1:3306) as there may be firewalls blocking the port or DNS not knowing this IP-address.
aljipa
  • 716
  • 4
  • 6