aspose file tools*
The moose likes JDBC and the fly likes Problem with Connecting to mysql using java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Problem with Connecting to mysql using java" Watch "Problem with Connecting to mysql using java" New topic
Author

Problem with Connecting to mysql using java

Karan Raj
Greenhorn

Joined: Jan 27, 2004
Posts: 16
Hi,
As a part of project i wrote the code to connect to mysql using java.In my system it is working fine.but when i tried on the server(even as root also) i am getting an error message.I am not able to sort out the what the problem could be..?
mycode is
{
...................................
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
}catch (Exception E) {
System.err.println("CONCEPT: Unable to Load Driver ");
E.printStackTrace();
}
try {
System.out.println("Connecting...");
Connection c = DriverManager.getConnection(
"jdbc:mysql://localhost/mysql?user=samurai&password=helloworld");
System.out.println("Connection ok: " + c);
System.out.println("Creating BankID table:");
Statement stmt=c.createStatement();
stmt.executeUpdate("use SST");
stmt.executeUpdate("CREATE TABLE BANKID (EID VARCHAR(20) UNIQUE)");
System.out.println("Table with following Attributes is created:");
ResultSet res=stmt.executeQuery("DESCRIBE BANKID");
while(res.next()){
String s=res.getString("Field");
System.out.println("-->"+s);
s=res.getString("Type");
System.out.println("-->"+s);
}
}catch (SQLException E) {
System.out.println ("SQLException: " + E.getMessage());
System.out.println ("SQLState: " + E.getSQLState());
System.out.println ("VendorError: " + E.getErrorCode());
}
}
public void addGID(String name){

String Query;
Query="INSERT INTO TABLE BANKID VALUES ( "+name +" )";
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
}catch (Exception E) {
System.err.println("CONCEPT: Unable to Load Driver ");
E.printStackTrace();
}..................
..............................

The above code is working fine in mysystem.but it's giving the following error when i try to run it on other system.
Error Message:
SQL Error: Data Source rejected for the establishment of the connection.user 'Host'@localhost is not allowed to connect to MySql Server.

Vendor Error Code: 1130

please help me

Thanks,
karan
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

you may need to update the server to allow the user to connect from that location, but I didn't think it was problem when connecting from the local machine.
Try this:

Note that you'll have to substitute for the database, username etc.
eg GRANT SELECT ON mysql.* TO ...
I'm confused why it is refusing 'HOST' when you're connecting with 'samurai' though...
Karan Raj
Greenhorn

Joined: Jan 27, 2004
Posts: 16
I already gave all privileges to user 'samurai'..
mysql> GRANT ALL PRIVILEGES ON SST.* TO 'samurai' IDENTIFIED BY 'helloworld';
i am able to access all tables in SST with samurai user manually. but i am getting error when i tried with my java code.I am not able to understand why it is giving ".... 'HOST '@localhost is not allowed to connect to MySql".
I tried the code even on the server system but it's giving same kind of error.
Varun Khanna
Ranch Hand

Joined: May 30, 2002
Posts: 1400
I hope you are not using "localhost" while making a remote connection.
Use IP address of the server instead of "localhost".


- Varun
 
 
subject: Problem with Connecting to mysql using java