我能在網上用phpmyadmin使用服務器的IP地址從myclient ..... 我試圖使用Java代碼無法從WAMP服務器訪問MySQL數據庫的在線
這裏以檢索從MySQL數據我的代碼
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package wamp; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; /** * * @author user */ public class 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://serverip: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:空,從服務器消息:「主機 ‘用戶PC.Home’是不允許連接到這個MySQL服務器」
你嘗試MySQL的管理員授予訪問權限 「任何主機」 使用%符號?這可能是一個特權問題。 –
添加新的帳戶: 用戶 'user1' @ 'exact_host' - 指定主機 CREATE USER '用戶1' @ 'exact_host' 或 用戶 'user1' @ '%' - 任何主機。 CREATE USER'user1'@'%' 授予您需要的權限並連接到新帳戶。 –