MySQL Forums
Forum List  »  Newbie

null, message from server: "Host '192.168.1.114' is not allowed to connect to this MySQL server"
Posted by: rais shaikh
Date: January 25, 2008 05:59AM

Hey ,
I am working on a java program in eclipse (Window XP) where
in need to connect to remote mysql database with is installed
in linux machine (fedora 7) , and i am facing a error when java program
connect to mysql database :
import java.sql.*;

public class HelloWorld {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("Checking if Driver is registered with DriverManager.");
DatabaseMetaData dbm;
Statement sql;
ResultSet rsl;

try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException cnfe) {
System.out.println("Couldn't find the driver!");
System.out.println("Let's print a stack trace, and exit.");
cnfe.printStackTrace();
System.exit(1);
}
System.out.println("Registered and loading the driver ok, so let's make a connection.");
Connection c = null;

try {
c = DriverManager.getConnection("jdbc:mysql://192.168.1.20:3306/ZoneVAXIN",
"root", "vaxinpro");
dbm = c.getMetaData();

System.out.println("Connection to "+dbm.getDatabaseProductName()+" "+
dbm.getDatabaseProductVersion()+" "+dbm.getUserName()+" "+dbm.getDriverName()+" successful.\n");
sql = c.createStatement(); //create a statement that we can use later

String sqlText1 = "create table xml_demo (code int, text varchar(20))";
System.out.println("Executing this command: "+sqlText1+"\n");
sql.executeUpdate(sqlText1);

String sqlText = "insert into xml_demo values (700,'AVALANCHE')";
System.out.println("Executing this command: "+sqlText+"\n");
sql.executeUpdate(sqlText);


sqlText = "insert into xml_demo (text)values (1200,'rais')";
System.out.println("Executing this command twice: "+sqlText+"\n");
sql.executeUpdate(sqlText);
sqlText = "insert into xml_demo values (900,'WEBSUITE')";
System.out.println("Executing this command twice: "+sqlText+"\n");
sql.executeUpdate(sqlText);

rsl = sql.executeQuery("select * from xml_demo");
if (rsl != null)
{
while (rsl.next())
{
System.out.println("code ="+rsl.getString("code")+
"; text = "+rsl.getString("text")+"\n");
}
}
rsl.close();


} catch (SQLException se) {
System.out.println("Couldn't connect: print out a stack trace and exit.");
se.printStackTrace();
System.exit(1);
}
if (c != null)
System.out.println(" We connected to the database!");
else
System.out.println("We should never get here.");

}

}
Program output :

Checking if Driver is registered with DriverManager.
Registered and loading the driver ok, so let's make a connection.
Couldn't connect: print out a stack trace and exit.
java.sql.SQLException: null, message from server: "Host '192.168.1.114' is not allowed to connect to this MySQL server"
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1056)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:957)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1079)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2032)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:729)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:46)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:302)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:283)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at HelloWorld.main(HelloWorld.java:27)

Options: ReplyQuote


Subject
Written By
Posted
null, message from server: "Host '192.168.1.114' is not allowed to connect to this MySQL server"
January 25, 2008 05:59AM
aa
June 17, 2008 01:22AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.