我已经使用phpmyadmin(wamp)创建了一个mysql数据库。我可以使用我的电脑的IP地址看到其他电脑的数据库。然而,当我运行java代码来检索数据库中的条目时,它会给出错误。我们已经禁用了主机的防火墙。 这里是我的代码:无法从phpMyAdmin(wamp)从其他电脑的MySQL数据库中检索输入
/*
- 要改变这种模板,选择Tools |模板*并在编辑器中打开 模板。 * /软件包wamp;
import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement;
/** * @author * *用户/公共类WAMP {
/**
* @param args the command line arguments
*/
// TODO code application logic here
public static void main(String args[]) throws InstantiationException, IllegalAccessException
{
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con = DriverManager.getConnection("jdbc:mysql://192.168.1.2:3306/test","root","");
Statement stmt=con.createStatement();
// stmt.executeUpdate("Insert into student values(1,'abc','nagpur')");
ResultSet rs= stmt.executeQuery("Select names from sample where id=15");
rs.next();
String name= rs.getString("names");
System.out.println(name);
System.out.println("DOne..");
//INSERT INTO `student`(`id`, `name`, `address`) VALUES (1,'amol','nagpur');
con.close();
}
catch(ClassNotFoundException | SQLException e){
System.out.println("error"+e);
}
}
}
这里是错误消息:
errorjava.sql.SQLException: null, message from server: "Host 'user-PC.Home' is not allowed to connect to this MySQL server
非常感谢。它确实有效。 – Amol