MySQL Forums
Forum List  »  Newbie

strange error appears while connecting to database via JDBC
Posted by: b.winkler
Date: April 04, 2005 03:32AM

hi everybody,

i have a strange problem and i'm trying to solve it since 3 weeks. now i'm out of ideas, why this happens and what i can do. maybe some of you can help me out.

i've written an applet, that uses the MySQL Connector for Java to connect to a MySQL-database v4.1.1.a-alpha running on a Windows XP system.

on two other systems (same MySQL-database version and also on WinXP), this runs perfectly well ... the applet connects to the database and everything is fine. but one of my systems makes me trouble with this.

when my applet connects to the database i get the following exception:

com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception:

** BEGIN NESTED EXCEPTION **

java.net.SocketException
MESSAGE: java.lang.reflect.InvocationTargetException

STACKTRACE:

java.net.SocketException: java.lang.reflect.InvocationTargetException
at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:191)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:280)
at com.mysql.jdbc.Connection.createNewIO(Connection.java:1765)
at com.mysql.jdbc.Connection.<init>(Connection.java:430)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:268)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at MyApplet.util.DB.connect(DB.java:45)
....

** END NESTED EXCEPTION **

at com.mysql.jdbc.Connection.createNewIO(Connection.java:1830)
at com.mysql.jdbc.Connection.<init>(Connection.java:430)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:268)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at MyApplet.util.DB.connect(DB.java:45)
....

i get this exception, even when i start the applet on the system where the database run's. but when i tell the applet there to connect to localhost instead of connecting to the ip of the system, everything is fine and the applet connects to the database without problems. sadly i can't let the applet alway's connect to localhost, because most users will use the applet from other hosts connected to the server.

i've written an java-application to check some properties in the database. this application also should connect via MySQL Connecter/J to the database. with this application it works to connect to the ip of the systems, the database run's on, but only, when the application is started on this system itself. when i run it on an other host, it connects unsuccessfully with the same exception.

in the table mysql.users i already set up a user for the applet and the application with all rights and privileges. for host i wrote %, because every forum tells me, that this should solve the problem. nope, it don't.

the string i use to connect the applet and the application to the database is:
jdbc:mysql://ServerIP:3306/myDB?user=root&password=xyz&connectTimeout=60
when i set ServerIP=localhost it works for both, but when ServerIP is the IP of the server, the applet doen't connect anymore and the application connects only when it runs on the server. no chance to connect from outside.

the realy strange thing about all this is, that i can use MySQLAdmin from any host to connect to this database and this works well. even every MySQL-Tool i use (like MySQLFront) can connect to the database with the user, i've set up for applet and application and as root (i set up a root account with a % in hosts for trying (unsuccessfully)). so everything can connect to the database, except the applications that use MySQL Connector/J.

i installed a network-sniffer to find out, whether MySQL Connector is blocked by something. nope, 6 packages arrive at port 3306 and also 6 go out when the Connector tries to connect.

the one and only difference between the two working systems and the one, that makes trouble is, that the Windows-User, that is logged in and runs the database is in the first two cases an Administrator and in the trouble-case a Main-User. i've allready tried to run the database as an Adminstrator on the troubling system, but this also don't works.

the reason becaus i use MySQL 4.1.1.a-alpha is, that i already had the newest version running, but i failed connecting with anything to the system from outside. only localhost connections could connect to the databases, although i tried to connect as root with a root account where hosts=%.

by the way: flushing privileges, the users, the hosts and the tables also don't solves the problem (event not restarting the database or the system). and the windows-firewall, that cames up with SP2 for XP, is disabled on both systems (my testing client(s) and the trouble making server).


many thanks for any of your suggestion. as mentioned above, i'm out of ideas, what could cause this problem and so i would appreciate everything i didn't tried out yet.

b. winkler

Options: ReplyQuote


Subject
Written By
Posted
strange error appears while connecting to database via JDBC
April 04, 2005 03:32AM


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.