473,387 Members | 1,549 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

MySQL ConnectorJ and remote machines

Ike
Let's say I have a MySQL 4.12 database, opened to the internet on
111.111.111.111 allowing all incoming and outgoing ports. I have a username
and password setup, which CAN connect to this database, from
222.222.222.222.

Also on 222.222.222.222, which is running Tomcat, I have a Java servlet,
called, say, servlet.class in WEB-INF/classes. servlet.class has permissions
755, as does WEB-INF/classes.

Additionally, I have on 222.222.222.222 under WEB-INF/lib
mysql-connector-java-3.1.7-bin.jar also with permissions 755.

The system (222.222.222.222) is running on Linux Kernel version
2.6.9-22.0.2.ELsmp. I am running Java 1.5.0_05. Bear in mind, the very same
parameters, from the same machine (222...) connect to the very same db
(111...) under php (so there is no firewall issue on 111...). Additionally,
if I run a MySQL DB (version 4.0.25) on 222... and connect to it (thus, on
'localhost') I can connect no problem. It is only when I go to connect to a
remote machine that I get the following stack trace:

java.sql.SQLException: Server connection failure during transaction.
Attempted reconnect 3 times. Giving up. at
com.mysql.jdbc.Connection.createNewIO(Connection.j ava:1704)
at com.mysql.jdbc.Connection.(Connection.java:491)
at
com.mysql.jdbc.NonRegisteringDriver.connect(NonReg isteringDriver.java:346)
at java.sql.DriverManager.getConnection(DriverManager .java:525)
at java.sql.DriverManager.getConnection(DriverManager .java:171)

I have ruled out firewall issues here (because I can connect from the same
machine with the same parameters under php), as well, I believe, permissions
issues here. Somehow, it (MySQL ConnectorJ) is NOT able to obtain a
connection. I have looked at the parameters passed through the call stack,
and they are correct. Is there a bug with MySQL Connector J for remote
connections? OR am I missing something stupid here?-Ike
May 23 '06 #1
7 2465
Ike wrote:
Let's say I have a MySQL 4.12 database, opened to the internet on
111.111.111.111 allowing all incoming and outgoing ports. I have a username
and password setup, which CAN connect to this database, from
222.222.222.222.

Also on 222.222.222.222, which is running Tomcat, I have a Java servlet,
called, say, servlet.class in WEB-INF/classes. servlet.class has permissions
755, as does WEB-INF/classes.

Additionally, I have on 222.222.222.222 under WEB-INF/lib
mysql-connector-java-3.1.7-bin.jar also with permissions 755.

The system (222.222.222.222) is running on Linux Kernel version
2.6.9-22.0.2.ELsmp. I am running Java 1.5.0_05. Bear in mind, the very same
parameters, from the same machine (222...) connect to the very same db
(111...) under php (so there is no firewall issue on 111...). Additionally,
if I run a MySQL DB (version 4.0.25) on 222... and connect to it (thus, on
'localhost') I can connect no problem. It is only when I go to connect to a
remote machine that I get the following stack trace:

java.sql.SQLException: Server connection failure during transaction.
Attempted reconnect 3 times. Giving up. at
com.mysql.jdbc.Connection.createNewIO(Connection.j ava:1704)
at com.mysql.jdbc.Connection.(Connection.java:491)
at
com.mysql.jdbc.NonRegisteringDriver.connect(NonReg isteringDriver.java:346)
at java.sql.DriverManager.getConnection(DriverManager .java:525)
at java.sql.DriverManager.getConnection(DriverManager .java:171)

I have ruled out firewall issues here (because I can connect from the same
machine with the same parameters under php), as well, I believe, permissions
issues here. Somehow, it (MySQL ConnectorJ) is NOT able to obtain a
connection. I have looked at the parameters passed through the call stack,
and they are correct. Is there a bug with MySQL Connector J for remote
connections? OR am I missing something stupid here?-Ike


There are several layers of complexity here (Tomcat configuration, data
source specification, remote access to a MySQL server, ...), and you
might find it useful to eliminate possible causes one at a time.

To that end, may I suggest that you write a very simple Java client
program, which you will run on 222.222.222.222 using the same MySQL
Connector/J JAR file and Java runtime as your Tomcat instance, and which
does nothing more than make a connection to your MySQL server on
111.111.111.111 using an explicit JDBC URL.

I'm talking about a "here's how you make a connection to a MySQL server
using JDBC" kind if program that you will find in chapter one of any
book on JDBC.

If *that* program fails with the same stack trace as you quoted above,
then you know the problem lies with the connection between the two
machines, and you can begin to investigate that part of your setup.

If, on the other hand, your simple JDBC client program *can* connect to
the MySQL server on the other machine, you will know that the problem
probably lies in your Tomcat setup.

This would be my approach to solving this problem. It's worked well for
me in the past, and saved me from hours of banging my head against the
wall in frustration :-)

David Harper
Cambridge, England
May 23 '06 #2
Ike wrote:
Additionally, I have on 222.222.222.222 under WEB-INF/lib
mysql-connector-java-3.1.7-bin.jar also with permissions 755.
For what it's worth, there is a 3.1.12 version of the MySQL
Connector/Java available now.
java.sql.SQLException: Server connection failure during transaction.
Attempted reconnect 3 times. Giving up. at
com.mysql.jdbc.Connection.createNewIO(Connection.j ava:1704) I have ruled out firewall issues here (because I can connect from the same
machine with the same parameters under php), as well, I believe, permissions
issues here. Somehow, it (MySQL ConnectorJ) is NOT able to obtain a
connection.


Can you test using the mysql command-line interface with the same user &
password parameters, to connect to MySQL on the remote host?

Can you share a few lines of Java code that you're using to connect?
In particular, can you show the JDBC URL you're using, and your
exception handling?

Or are you using a Tomcat <resource> to connect? I've seen other folks
describe difficulty getting that to work.

I've also seen people have difficulty using the URL format with the
username & password included as URL parameters. It seems to be more
reliable to use the JDBC getConnection() method with username and
passwords as separate method arguments.

Regards,
Bill K.
May 23 '06 #3
Ike

"Bill Karwin" <bi**@karwin.com> wrote in message
news:e4*********@enews1.newsguy.com...

Can you test using the mysql command-line interface with the same user &
password parameters, to connect to MySQL on the remote host?

I cannot because it is on a 3rd part server (i.e. 222.... is a 3rd part
server running Tomcat). Although, I CAN connect with those parameters, say,
through php MyAdmin
Can you share a few lines of Java code that you're using to connect?
In particular, can you show the JDBC URL you're using, and your
exception handling?
private Connection makeNewConnection()
throws SQLException {
try {
// Load database driver if not already loaded
Class.forName(driver);//driver is org.gjt.mm.mysql.Driver
// Establish network connection to database
Connection connection =
DriverManager.getConnection(url, username, password);//url is
"jdbc:mysql://67.103.171.173:3306/ggripdb?autoReconnect=true"
return(connection);
} catch(Exception cnfe) {
throw new SQLException("Can't connect with: " +
driver+" to "+url);
}
}
Or are you using a Tomcat <resource> to connect? I've seen other folks
describe difficulty getting that to work.
No
I've also seen people have difficulty using the URL format with the
username & password included as URL parameters. It seems to be more
reliable to use the JDBC getConnection() method with username and
passwords as separate method arguments.
I thnk that is what I am passing here, yes? Thanks Bill, Ike
Regards,
Bill K.

May 24 '06 #4
Ike
THank you David. Unfortunately, the 222.. machine is hosted by a third
party. I think though, if I send them a simple java JDBC app as you suggest,
and obtain the stack trace, it may tell me something.

Thanks Again! -Ike
May 24 '06 #5
Ike
One thing that IS different on the machines I am connecting to remotely is
that on the remote machines:

set password for me@'%'=OLD_PASSWORD('mypassword');

I'm wondering if that is not screwing it here? Is there a way to use MySQL
ConnectorJ then handle the new/old password issue so that it is compatible
with php4 ? Thanks, Ike
May 24 '06 #6
Ike wrote:
try {
// Load database driver if not already loaded
Class.forName(driver);//driver is org.gjt.mm.mysql.Driver
// Establish network connection to database
Connection connection =
DriverManager.getConnection(url, username, password);//url is
"jdbc:mysql://67.103.171.173:3306/ggripdb?autoReconnect=true"
return(connection);
} catch(Exception cnfe) {
throw new SQLException("Can't connect with: " +
driver+" to "+url);
}


This message thrown by your new SQLException doesn't match the error
message you reported in your original post. Are you sure this is the
point at which the exception is being thrown?

Also, by catching the exception and doing nothing with it, you have
obscured the cause of the exception. Your exception object is named
cnfe, so I would infer that you believe the only exception that can
occur is a ClassNotFoundException. The DriverManager.getConnection()
can throw different types of exceptions, and with different messages,
but your code is ignoring this important diagnostic information.

Regards,
Bill K.
May 24 '06 #7
Ike wrote:
One thing that IS different on the machines I am connecting to remotely is
that on the remote machines:

set password for me@'%'=OLD_PASSWORD('mypassword');

I'm wondering if that is not screwing it here? Is there a way to use MySQL
ConnectorJ then handle the new/old password issue so that it is compatible
with php4 ? Thanks, Ike


I've been burned by this myself when connecting to MySQL servers from
Perl scripts which use out-of-date versions of the MySQL DBI module
(Perl's equivalent, very loosely, of JDBC).

However, it should not affect Java clients which use a reasonably recent
version of Connector/J.

I have a MySQL 4.1 server which has some users with old-format passwords
and some users with new-format passwords. I can successfully connect to
the server using my simple Java program as both types of user. I guess
the code inside Connector/J figures out which type of authentication to
use automatically.

David Harper
Cambridge, England
May 25 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Phil Powell | last post by:
I've read some online resources that utilize various MySQL command-line actions to migrate data from Access to MySQL. The situation is this: a group of co-workers of mine will be using an Access...
0
by: gunzip | last post by:
I want to setup PHP5 to access MySQL 4.0 on the local (Fedora 2) machine and 4.1 on a remote (OS X) machine. I've compiled PHP5 successfully using '--with-mysql=/usr' to find the local MySQL 4.0...
7
by: aa | last post by:
If I have an MySQL database on my local w2k, how do I transfer it onto my ISP server? The ISP gave me the name of an empty MySQL database they set up for me, the username and the password with no...
0
by: Mark | last post by:
Using a Java program, I can connect to the test database in MySQL. The test database is installed using a MySQL utility, and it can be accessed by any user without supplying a password. The...
0
by: Paul Bergin | last post by:
Hi, I am connecting to a mysql 4.1 db with mysql connectorJ 3.0.7 and when I run a meta.getColumns(null, null, tableName, "%") on one particular table the following exception is thrown. ...
16
by: MLH | last post by:
Using MS Access, I have attached to MySQL servers in other states and other countries on the other side of my router. But when I use the MySQL ODBC driver 3.51 to connect to a MySQL server on my...
10
by: Simon | last post by:
Hi, I need to export a 200MB database from one domain to another. phpMyAdmin timeout after a while and is not ideal. I don't mind spending money if I have to but this is rather urgent. I...
5
by: Ike | last post by:
Through Java, I am attempting to connect to a MySQL 4.12 server on a remote computer. I can connect fine via php. I cann connect fine via Java, through a servlet, when the servlet is on the same...
2
by: Adam McCormack | last post by:
Good morning! I am on a project where we are migrating a site running on perl and mysql on IIS. The current configuration is with everything on one server, both IIS and MySQL. The new...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.