JDBC/JSP/MySQL Code works from my local machine, but not on server

Hi there!

I've been struggling with this problem for a while.

I have a database from which I need to read and display some data on a browser. (The database is set up for remote access).

I'm using the following JSP/JDBC code to do that.

-

Class.forName ("com.mysql.jdbc.Driver").newInstance();

out.println("
Connecting to DB...Pls. Wait
");

Connection con = DriverManager.getConnection("url","user","pwd");

if(con.isClosed())

out.println("


" +"Could NOT connect to MySQL Database...");

else out.println("
CONNECTED !!!
");

Statement stmt = con.createStatement();

results = stmt.executeQuery("SELECT * FROM TableName" );

--

When I run this of my local machine, it works fine. But when I upload it to a server, it doesn't run through. I dont get either the connected or not connected message.

I tried this piece of code that I found online to check the driver.

-

/*Driver d = (Driver)Class.forName("com.mysql.jdbc.Driver").newInstance();

out.println("
Got a driver instance. ");

if (d.acceptsURL(url)) out.println("
The driver does accept my URL");

else out.println("
The driver doesn't like the URL I'm trying"); */

I ran it off the server and it worked. I got the outputs --Got a driver instanceandThe driver does accept my URL

I'm unable to figure out why this code can be run locally from my machine, but not from a different location. The database is NOT on my machine.

Any inouts will be really appreciated.

I'm using an Apache Tomcat container and the database is MySQL.

[1698 byte] By [delrama] at [2007-11-27 4:34:28]
# 1

Just wanted to mention

The database is on another (3rd) machine.

So I have

1. My local machine

2. Database hosted on a 2nd machine

3. Place I'm moving my code to (its basically a hosting account provided by an external company)

I can access the database from my local machine. However, when I move the code over to another machine, it doesn't work.

delrama at 2007-7-12 9:44:24 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 2
Maybe you're using internal IP's or hostnames instead of external IP's or hostnames?
BalusCa at 2007-7-12 9:44:24 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 3
Hi BalusCCan you pls. elaborate?I'm using a url string in this format jdbc:mysql://blah.blah.net:port/dbname","user","pwd"Thanks for your time!D
delrama at 2007-7-12 9:44:24 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 4
Internal IP's and hostnames like "192.168.0.1" and "localhost" are not externally accessible.If this is actually an external hostname, then you might doublecheck the proxy/firewall/router settings if it allows the port used.
BalusCa at 2007-7-12 9:44:24 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...