我在本地系统中使用它
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/dbname", "userid", "password");
两者都工作正常。但是当我尝试用这个连接服务器时
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/dbname", "userid", "password");
它不工作..! 数据库用户名和密码都是正确的那么我如何连接到我的数据库服务器。有人可以发布解决方案吗?
最佳答案
你上面的例子似乎有点不正确。两者都指向 localhost 域,但您的问题可能与以下事实有关:您的数据库默认情况下不允许该特定用户名 + 数据库组合的远程连接。
mysql> CREATE DATABASE foo;
mysql> GRANT ALL ON foo.* TO bar@'192.168.1.1' IDENTIFIED BY 'PASSWORD';
关于java - 如何从 jsp 连接 MySQL 数据库与我的网络服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24656232/