我已經使用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