Hello All!
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.
[CODE=java] ----------------------------------------------------------------------------------------------
Class.forName ("com.mysql.jdb c.Driver").newI nstance();
out.println("<B R> Connecting to DB...Pls. Wait <BR>");
Connection con = DriverManager.g etConnection("u rl","user","pwd ");
if(con.isClosed ())
out.println("<B R><BR><BR>" +"Could NOT connect to MySQL Database...");
else out.println("<B R> CONNECTED !!! <BR>");
Statement stmt = con.createState ment();
results = stmt.executeQue ry("SELECT * FROM TableName" );
-----------------------------------------------------------------
[/CODE]
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.
[CODE=java]
--------------------------------------------------------------------------
Driver d = (Driver)Class.f orName("com.mys ql.jdbc.Driver" ).newInstance() ;
out.println("<B R>Got a driver instance. ");
if (d.acceptsURL(u rl)) out.println("<B R>The driver does accept my URL");
else out.println("<B R>The driver doesn't like the URL I'm trying");
---------------------------------------------------------------------------
[/CODE]
I ran it off the server and it worked. I got the outputs --Got a driver instance and The 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.
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.
[CODE=java] ----------------------------------------------------------------------------------------------
Class.forName ("com.mysql.jdb c.Driver").newI nstance();
out.println("<B R> Connecting to DB...Pls. Wait <BR>");
Connection con = DriverManager.g etConnection("u rl","user","pwd ");
if(con.isClosed ())
out.println("<B R><BR><BR>" +"Could NOT connect to MySQL Database...");
else out.println("<B R> CONNECTED !!! <BR>");
Statement stmt = con.createState ment();
results = stmt.executeQue ry("SELECT * FROM TableName" );
-----------------------------------------------------------------
[/CODE]
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.
[CODE=java]
--------------------------------------------------------------------------
Driver d = (Driver)Class.f orName("com.mys ql.jdbc.Driver" ).newInstance() ;
out.println("<B R>Got a driver instance. ");
if (d.acceptsURL(u rl)) out.println("<B R>The driver does accept my URL");
else out.println("<B R>The driver doesn't like the URL I'm trying");
---------------------------------------------------------------------------
[/CODE]
I ran it off the server and it worked. I got the outputs --Got a driver instance and The 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.
Comment