Signup · Login
Stardeveloper.com  
Home · Tutorials · Forums · ASP.NET Newsletter Application · Web Hosting Plans · Faisal Khan's Blog · Contact
Forums : J2EE : JDBC : how to connect remote MYSQL using java Signup · Login
Author Thread
how to connect remote MYSQL using java
Posted in tutorial: Connecting to a MySQL Database using Connector/J JDBC Driver
·  rmethuku
User
Joined: 19 Nov 2004
Total Posts: 1

how to connect remote MYSQL using java

Posted: 19 Nov 2004
hello everybody,

iam using like this

import java.sql.*;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.net.*;

public class Jdbc1 {

public static void main(String args[]) {
Connection con = null;

try {
Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection("jdbc:mysql://remoteip/test","root ", "secret");
Statement st = con.createStatement();
ResultSet rs = st.executeQuery("select * from sample");
while(rs.next())
{
System.out.println("Name " + rs.getString(1));
System.out.println("Id " + rs.getString(2));
}
} catch(Exception e) {
e.printStackTrace();
System.out.println("Exception: " + e.getMessage());
} finally {
try {
if(con != null)
con.close();
} catch(SQLException e) {}
}
}
}

here iam getting this type of exception

java.sql.SQLException: Data source rejected establishment of connection, messag
e from server: "Host 'RAMESH' is not allowed to connect to this MySQL server"
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:639)
at com.mysql.jdbc.Connection.createNewIO(Connection.java:1774)
at com.mysql.jdbc.Connection.<init>(Connection.java:440)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java
:400)
at java.sql.DriverManager.getConnection(DriverManager.java:512)
at java.sql.DriverManager.getConnection(DriverManager.java:171)
at Jdbc1.main(Jdbc1.java:17)
Exception: Data source rejected establishment of connection, message from serve
r: "Host 'RAMESH' is not allowed to connect to this MySQL server"



please help me

regards
Ramesh

ramesh
·  nellios
User
Joined: 8 Jun 2005
Total Posts: 1
how to connect remote (or localy) MYSQL using java
Posted: 8 Jun 2005
I was having the exact the same problem with local connection in unix.

At first I tried to connect to the server with:
#telnet mysq_host 3306

and I could connect to the port, so it was not a matter of security(firewall setting, etc). So it could only be mysql issue. So I tried:

#mysql
mysql > GRANT select,insert,update,delete,create,drop ON DB.* TO DB_USERNAME@HOST IDENTIFIED BY 'DB_PASSWORD';

and it worked for me. Hope this helps you !!!

Ioannis D. Canellos
·  ivha21
User
Joined: 7 Dec 2005
Total Posts: 1
Connecting to a MySQL Server from a different machine
Posted: 7 Dec 2005
Hello everyone,

I tried to connect to a mysql server from another machine with the jdbc driver as given in this website, but my connection was rejected by the server. I got a message:

Exception: Data source rejected establishment of connection, message from server: "Host '177-175.mam.umd.edu' is not allowed to connect to this MySQL server"

I'm using Eclipse to connect directly, I have the jar files in there ( I assumed that's not the problem), the connection string is correct which is like
con = DriverManager.getConnection("jdbc:mysql://hostname:port/test","root", "password");

I'm not connecting remotely, but I'm trying to connect from a different machine. Can somebody please help me with this...? Thank you!


~M. Nasrun
·  kott_kvarn
User
Joined: 29 Mar 2006
Total Posts: 1
Connecting to a MySQL Server from a different machine
Posted: 29 Mar 2006
Hi,

I had the same problem. All I had to do was to make sure the username I logged in with had the right to log on to the server from a remote host.

For example you can change these privilegies in phpmyadmin.
·  irannaece2009
User
Joined: 29 Jun 2010
Total Posts: 1
Re: how to connect remote MYSQL using java
Posted: 29 Jun 2010
import java.sql.*;
import java.sql.DriverManager;
import java.sql.SQLException;


public class jdbc1 {

public static void main(String args[]) {
Connection con = null;

try {
Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root ", "secret");
Statement st = con.createStatement();
ResultSet rs = st.executeQuery("select * from sample");
while(rs.next())
{
System.out.println("Name " + rs.getString(1));
System.out.println("Id " + rs.getString(2));
}
} catch(Exception e) {
e.printStackTrace();
System.out.println("Exception: " + e.getMessage());
} finally {
try {
if(con != null)
con.close();
} catch(SQLException e) {}
}
}
}
Want to leave a comment? Login or Register for free!

Users Subscribed To This Thread
irannaece2009  

Users Who Have Visited This Thread In Last 24 Hours
39 Visitors

Login to post a comment or start a new thread
UserName Or Email Address:       Password:       Auto-Login:    
· Create New User Account
· Send Forgotten Password by Email
 
© 1999 - 2010 Stardeveloper.com, All Rights Reserved.