String name = "";
String port = "3306";
String user = "root";
String pass = "";
String dbname = "atm";
String host="192.168.5.219"; // my local host ip address
// I want to do this only with IP address..
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
String url = "jdbc:mysql://"+host+":"+ port + "/" + dbname;
System.out.println("URL:" + url);
//Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection(url, user, pass);
String qry2 = "select * from atm";
Statement st = con.createStatement();
ResultSet rs = st.executeQuery(qry2);
while (rs.next()) {
name = rs.getString("name");
System.out.println("Name:" + name);
j.setText(""+name);
}
rs.close();
st.close();
con.close();
} catch (Exception e) {
javax.swing.JOptionPane.showMessageDialog(null, e.getMessage());
System.out.println(e.getMessage());
}
When I run this I got an error:
error>> null, message from server: "Host 'DEEPAK-PC' is not allowed to connect to this MySQL server"
Actually I want to make a program that takes data from another PC connected to my LAN network in school. So that's why I want to do this with IP address.