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){
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.
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
posted
0
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.