Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / May 2007

Tip: Looking for answers? Try searching our database.

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

Thread view: 
udelram@gmail.com - 16 May 2007 16:14 GMT
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.

----------------------------------------------------------------------------------------------
[B]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" );[/B]

-----------------------------------------------------------------

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 --[I]Got a
driver instance [/I]and [I]The driver does accept my URL[/I]

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.
Lothar Kimmeringer - 16 May 2007 18:14 GMT
> 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.

Regards, Lothar
Signature

Lothar Kimmeringer                E-Mail: spamfang@kimmeringer.de
              PGP-encrypted mails preferred (Key-ID: 0x8BC3CD81)

Always remember: The answer is forty-two, there can only be wrong
                questions!

Lew - 16 May 2007 22:26 GMT
>> 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
[quoted text clipped - 3 lines]
> 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.

Signature

Lew



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.