• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Problem with Connecting to mysql using java

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 1400
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I hope you are not using "localhost" while making a remote connection.
Use IP address of the server instead of "localhost".
 
Don't touch me. And dont' touch this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic