wood burning stoves 2.0*
The moose likes JSP and the fly likes JSP mySQL exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "JSP mySQL exception" Watch "JSP mySQL exception" New topic
Author

JSP mySQL exception

Chris Cingrani
Ranch Hand

Joined: Nov 21, 2000
Posts: 69
I am trying to connect to a mySQL database that is hosted remotely. I am sure I am putting in the correct information to correct, however, every time I try and run the .jsp code, it will display the column headers and then go to the exception, with no error being displayed. Here is the code I am using. Any thoughts would be appreciated!
Thanks -
Chris
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

No error message at all?? Anything else you can give us? without an error, I don't see anything wrong with your code.


GenRocket - Experts at Building Test Data
Chris Cingrani
Ranch Hand

Joined: Nov 21, 2000
Posts: 69
Gregg -
All it displays is this:
Begin Exception Dump
End Exception
Not much to go on, which is why I am baffled. I don't understand why the e.getMessage() doesn't return something.
Chris
Malhar Barai
Author
Ranch Hand

Joined: Aug 17, 2001
Posts: 399
Originally posted by Chris Cingrani:
Gregg -
All it displays is this:
Begin Exception Dump
End Exception
Not much to go on, which is why I am baffled. I don't understand why the
e.getMessage() doesn't return something.

hi dear,
Have you tried writing e.printStackTrace(out), bcoz i dont think your program know where to show the error. "out" is defined as an object of PrintWriter, & that would print the error on the screen.
if you are using tomcat, you can check the logs at <tomcat-home>/logs to find the error. You can check file with today's date as its filename.
hth
MB
[ August 04, 2003: Message edited by: Malhar Barai ]

Malhar Barai
SOA & Java Book
Sam Walker
Ranch Hand

Joined: Nov 06, 2002
Posts: 65
Hi,
Hi I think the problem may be that url cannot include user id and password. There�s another getConnection method specifically for passing user and password. replace:

conn = DriverManager.getConnection("jdbc:mysql://localhost/dbName?user=me&password=pass");

with getConnection("jdbc:mysql://localhost/dbName", "me","pass");

The getConnection() statement is a regular JDBC statement and the syntax applied to it must be based on JDBC specification.
Malhar Barai
Author
Ranch Hand

Joined: Aug 17, 2001
Posts: 399
Originally posted by Sam Walker:
Hi,
Hi I think the problem may be that url cannot include user id and password. There’s another getConnection method specifically for passing user and password. replace:
with getConnection("jdbc:mysql://localhost/dbName", "me","pass");

The getConnection() statement is a regular JDBC statement and the syntax applied to it must be based on JDBC specification.

hi Sam
That can't be a problem because you can indeed include the username & password in the URL.
chk the following link
User & password
hth
MB
Chris Cingrani
Ranch Hand

Joined: Nov 21, 2000
Posts: 69
Thanks to everyone for their replies thusfar. In regards to Malhar's comments, I wanted to mention that the Exception handler will output a message at times. For instance, if it cannot find the jdbc.Driver class the message displays as follows:
Begin Exception Dump
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
End Exception
So, the messages will display, it's just that no errors are coming back in this instance. Also, I can't access the log files for Tomcat because it is hosted remotely.
Any other ideas?
Thanks -
Chris
Malhar Barai
Author
Ranch Hand

Joined: Aug 17, 2001
Posts: 399
hi
Exception object "e" just gets the error message by e.getMessage(), but not the stack trace.
To get the error trace on your page, you indeed have to specify e.printStackTrace(out); , give it a try, if that doesnt work, you can get the complete trace in a text file, try the following code :

View the text file, & you can know the error, w/out seeing the log file of Tomcat.
hth
MB
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

But you should just be able to log the stack trace directly to the screen using e.printStackTrace( new java.io.PrintWriter( out ) );
Sam Walker
Ranch Hand

Joined: Nov 06, 2002
Posts: 65
Hi Chris,
How sure are you that all the jar files you need are in your classpath or where they can be found? Could this be a situation that the class loader finds two different versions of the same class? That happened to me once and I was getting strange problems.
Chris Cingrani
Ranch Hand

Joined: Nov 21, 2000
Posts: 69
I made the modifications Malhar and David recommended, but still no difference. There isn't anything being displayed between Begin Exception Dump and End Exception.
This is starting to drive me nuts....
Chris
Asher Tarnopolski
Ranch Hand

Joined: Jul 28, 2001
Posts: 260
did you try to do this:
%>Begin Exception Dump<P><%
<%=e.getMessage())%>
<%= e %><P>End Exception<%
?
and if thisdoesn't help, did you try to totally remove user/password part from your url? try to run it without them.
[ August 05, 2003: Message edited by: Asher Tarnopolski ]

Asher Tarnopolski
SCJP,SCWCD
Malhar Barai
Author
Ranch Hand

Joined: Aug 17, 2001
Posts: 399
hi again

if the database is hosted remotely, why are you using "localhost" in the connection string. Shouldn't it be the IP of the remote host.

hth
MB
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSP mySQL exception
 
Similar Threads
reading data from jsp page to another jsp page using request.getParameter
Displaying a ResultSet Problem
servlet-jdbc - internal servlet error (error:500)
Calling another servlet
compiling jsp