 |
AppletTalk.com Java discussions newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Guest
|
Posted: Wed May 16, 2007 8:15 pm Post subject: JDBC/JSP/MySQL Code works from my local machine, but not on |
|
|
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("<BR> Connecting to DB...Pls. Wait <BR>");
Connection con = DriverManager.getConnection("url","user","pwd");
if(con.isClosed())
out.println("<BR><BR><BR>" +"Could NOT connect to MySQL
Database...");
else out.println("<BR> CONNECTED !!! <BR>");
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("<BR>Got a driver instance. ");
if (d.acceptsURL(url)) out.println("<BR>The driver does accept my
URL");
else out.println("<BR>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 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. |
|
| Back to top |
|
 |
Guest
|
Posted: Wed May 16, 2007 8:52 pm Post subject: Re: JDBC/JSP/MySQL Code works from my local machine, but not |
|
|
Just wanted to add that 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 it from my local machine. However, when I move the code
over to another machine, it doesn't work.
Thanks,
D |
|
| Back to top |
|
 |
Lew Guest
|
Posted: Thu May 17, 2007 2:26 am Post subject: Re: JDBC/JSP/MySQL Code works from my local machine, but not |
|
|
Lothar Kimmeringer wrote:
| Quote: | udelram (AT) gmail (DOT) com wrote:
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.
You get an exception and that would tell you what the problem
is. Because you don't catch it, it should be found in the
server's logfile.
|
I'm cross-posting Lothar's answer back to clj.help to benefit those not aware
of the multi-posting of this query who thus might have missed the answer.
To the OP: Please do not multi-post.
--
Lew |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|