473,698 Members | 1,840 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.22 2) 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.SQLExc eption: Server connection failure during transaction.
Attempted reconnect 3 times. Giving up. at
com.mysql.jdbc. Connection.crea teNewIO(Connect ion.java:1704)
at com.mysql.jdbc. Connection.(Con nection.java:49 1)
at
com.mysql.jdbc. NonRegisteringD river.connect(N onRegisteringDr iver.java:346)
at java.sql.Driver Manager.getConn ection(DriverMa nager.java:525)
at java.sql.Driver Manager.getConn ection(DriverMa nager.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 2496
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.22 2) 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.SQLExc eption: Server connection failure during transaction.
Attempted reconnect 3 times. Giving up. at
com.mysql.jdbc. Connection.crea teNewIO(Connect ion.java:1704)
at com.mysql.jdbc. Connection.(Con nection.java:49 1)
at
com.mysql.jdbc. NonRegisteringD river.connect(N onRegisteringDr iver.java:346)
at java.sql.Driver Manager.getConn ection(DriverMa nager.java:525)
at java.sql.Driver Manager.getConn ection(DriverMa nager.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.SQLExc eption: Server connection failure during transaction.
Attempted reconnect 3 times. Giving up. at
com.mysql.jdbc. Connection.crea teNewIO(Connect ion.java: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.co m> wrote in message
news:e4******** *@enews1.newsgu y.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 makeNewConnecti on()
throws SQLException {
try {
// Load database driver if not already loaded
Class.forName(d river);//driver is org.gjt.mm.mysq l.Driver
// Establish network connection to database
Connection connection =
DriverManager.g etConnection(ur l, username, password);//url is
"jdbc:mysql ://67.103.171.173: 3306/ggripdb?autoRec onnect=true"
return(connecti on);
} catch(Exception cnfe) {
throw new SQLException("C an'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_PASS WORD('mypasswor d');

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(d river);//driver is org.gjt.mm.mysq l.Driver
// Establish network connection to database
Connection connection =
DriverManager.g etConnection(ur l, username, password);//url is
"jdbc:mysql ://67.103.171.173: 3306/ggripdb?autoRec onnect=true"
return(connecti on);
} catch(Exception cnfe) {
throw new SQLException("C an'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 ClassNotFoundEx ception. The DriverManager.g etConnection()
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_PASS WORD('mypasswor d');

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
3269
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 db in a shared source (for now, a directory.. ???) to be able to generate reports on the fly. What they want to do is to be able to migrate that data to a MySQL db instance that currently exists on a different server. What would be the best...
0
1424
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 but what should I use to configure a connection to the remote MySQL 4.1 server? --with-mysqli=user:password@osx:/path/to/mysql41 ???? Can PHP5 even be configured to use both versions of MySQL?
7
2867
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 further explanations. I came here from ASP/Access where I was just uploading a mdb file into my webspace. But with MySQL there should be a different procedure, should it not?
0
2399
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 relevant lines in my Java (Java version 1.4.1) code are: Connection con = null; String url = "jdbc:mysql:///test"; // <== no user or password specified con = DriverManager.getConnection(url); However, when I try to connect to the accounting...
0
1599
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. Exception occurred during event dispatching: java.lang.StringIndexOutOfBoundsException: String index out of range: -1 at java.lang.String.substring(String.java:1497) at com.mysql.jdbc.DatabaseMetaData.getColumns(DatabaseMetaData.java:877)
16
27914
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 own LAN, the driver tells me it cannot make the connection. Here are the ODBC driver connection parms: Data Source Name: (free field - name my "my linux box" will do nicely) Host/Server Name (or IP) - something like MSQLUserName@ServerName.net...
10
3595
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 only work on win32 machines but the servers are Unix machines. I don't have command line access to the servers.
5
3852
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 machine (localhost) as the MySQL DB. However, when they are on different machines with different IPs, calling across the Internet (and there are no firewall issues -- I can connect fine to the remote MySQL DB via php from the same machine, not...
2
2261
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 configuration has IIS on one server, and MySQL on another, both machines are approximately equivalent to the old (aka current) box power wise.. The problem I am having is that a given script (granting it is based on an ugly query with 7 joins) runs in a...
0
8668
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9014
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8885
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7708
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6515
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4612
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3037
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2320
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1995
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.