这里我试图连接到多个数据库这里是我的代码,这个代码在本地机器上工作正常但是当我上传到在线这不起作用可能我得到任何帮助提前谢谢。
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);
}
}
当我问我的托管服务提供商他给我发了什么问题时,这对我来说是个新鲜的
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)
答案 0 :(得分:0)
也有可能出错的事情。但正如您已经提到的那样,一旦您尝试从外部访问数据库时问题就会发生,这种异常消息可能表明您的数据库无法访问,原因如下:
- 在 my.cnf 中,您应该验证--skip-networking已被注释掉:
[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
那就是说你的数据库通过TCP / IP接受消息