【百分以上】java通过jdbc连接mysql的问题……

来源:百度知道 编辑:UC知道 时间:2024/06/05 15:01:40
message from server: "Host '06JSJX33' is not allowed to connect to this MySQL server"
连接的时候出现上面的错误……源码如下:数据库在局域网的另外一台机子上,那个06JSJX33是我的本机……这是怎么回事?好像是不允许连接那个mysql服务器……
package zhixing;
import java.sql.*;
public class Nbmail {

private String dbURL="jdbc:mysql://211.64.40.98/our?useUnicode=true&characterEncoding=gb2312"; // 数据库标识名
private String user="root"; // 数据库用户
private String password="123456"; // 数据库用户密码

public void SearchDemo(){
try {
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
Connection con=DriverManager.getConnection(dbURL,user,password); //获取连接
String sqlStr="select * from usr"; //SQL查询语句
Statement st=con.createStatement(); //获取Statement对象
ResultSet rs=st.executeQuery(sqlStr); //执行查询
String name; //查询结果
while (rs.next()){ //遍历ResultSet
name=

占位...
更改远程连接权限
update user set host="%" where user="root"

GRANT ALL PRIVILEGES ON [dbname].* to
'[user]'@'[hostname]' identified by
'[password]'

给你的user赋予权限。其中,将host字段的值改为%就表示在任何客户端机器上能以user用户登录到mysql服务器,建议在开发时设为%。

例如:
grant all privileges on *.* to 'root'@'%' identified by 'rootPassword' with grant option

记住重新加载授权表:flush PRIVILEGES,或者将mysql重启一次即可。

在主机IP后面加一个3306端口号试试。
private String dbURL="jdbc:mysql://211.64.40.98:3306/our"

看看是不是放火墙什么的栏着了