aspose file tools*
The moose likes JDBC and the fly likes  JSP + Mysql connection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark " JSP + Mysql connection " Watch " JSP + Mysql connection " New topic
Author

JSP + Mysql connection

Miguel Enriquez
Ranch Hand

Joined: Mar 13, 2004
Posts: 94
hi all when i test the code, say me the message:
Ooops, something bad happened:

1) How know what is the exact error?
2) how know if the problem is about connector?


<HTML>
<HEAD><TITLE>Employee List</TITLE></HEAD>
<BODY>
<%@ page import="java.sql.*" %>
<TABLE BORDER=1 width="75%">
<TR><TH>Last Name</TH><TH>First Name</TH></TR>
<%
Connection conn = null;
Statement st = null;
ResultSet rs = null;
try {
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
conn =DriverManager.getConnection("jdbc:mysql://localhost/embarques" +
"user=embarques&password=embarquesX2006X");

st = conn.createStatement();
rs = st.executeQuery("select * from tlogin");
rs.first();
while(rs.next()) {
%>
<TR><TD><%= rs.getString("iloginid") %></TD>
<TD><%= rs.getString("cloginusua") %></TD></TR>
<%
}
%>
</TABLE>
<%
} catch (Exception ex) {
ex.printStackTrace();
%>
</TABLE>
Ooops, something bad happened:
<%

} finally {
if (rs != null) rs.close();
if (st != null) st.close();
if (conn != null) conn.close();
}
%>
</BODY>
</HTML>
[ March 24, 2007: Message edited by: Bear Bibeault ]
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336


1) How know what is the exact error?
2) how know if the problem is about connector?

Look at the stack trace in the console or log.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Miguel Enriquez
Ranch Hand

Joined: Mar 13, 2004
Posts: 94
can you tell me how check???
wich log file need check?

thanks a lot



C:\ProgramInstall\Apache Software Foundation\Tomcat 6.0\logs>dir
Volume in drive C has no label.
Volume Serial Number is 5A0A-0BB5

Directory of C:\ProgramInstall\Apache Software Foundation\Tomcat 6.0\logs

23/03/2007 02:29 AM <DIR> .
23/03/2007 02:29 AM <DIR> ..
07/03/2007 03:25 AM 0 admin.2007-03-07.log
09/03/2007 12:05 AM 0 admin.2007-03-09.log
14/03/2007 01:30 AM 0 admin.2007-03-14.log
22/03/2007 12:44 AM 0 admin.2007-03-22.log
23/03/2007 02:29 AM 0 admin.2007-03-23.log
07/03/2007 07:18 AM 17,351 catalina.2007-03-07.log
09/03/2007 12:05 AM 1,715 catalina.2007-03-09.log
14/03/2007 01:56 AM 7,117 catalina.2007-03-14.log
15/03/2007 03:13 AM 334 catalina.2007-03-15.log
22/03/2007 01:43 PM 2,335 catalina.2007-03-22.log
23/03/2007 02:29 AM 8,212 catalina.2007-03-23.log
07/03/2007 03:25 AM 0 host-manager.2007-03-07.log
09/03/2007 12:05 AM 0 host-manager.2007-03-09.log
14/03/2007 01:30 AM 0 host-manager.2007-03-14.log
22/03/2007 12:44 AM 0 host-manager.2007-03-22.log
23/03/2007 02:29 AM 0 host-manager.2007-03-23.log
07/03/2007 07:18 AM 1,292 jakarta_service_20070307.log
09/03/2007 12:05 AM 154 jakarta_service_20070309.log
15/03/2007 03:13 AM 1,204 jakarta_service_20070314.log
22/03/2007 01:42 PM 408 jakarta_service_20070322.log
23/03/2007 02:29 AM 154 jakarta_service_20070323.log
07/03/2007 03:25 AM 0 localhost.2007-03-07.log
09/03/2007 12:05 AM 0 localhost.2007-03-09.log
14/03/2007 01:30 AM 0 localhost.2007-03-14.log
22/03/2007 12:44 AM 0 localhost.2007-03-22.log
23/03/2007 02:29 AM 0 localhost.2007-03-23.log
07/03/2007 03:25 AM 0 manager.2007-03-07.log
09/03/2007 12:05 AM 0 manager.2007-03-09.log
14/03/2007 01:30 AM 0 manager.2007-03-14.log
22/03/2007 12:44 AM 0 manager.2007-03-22.log
23/03/2007 02:29 AM 0 manager.2007-03-23.log
07/03/2007 03:24 AM 0 stderr_20070307.log
09/03/2007 12:05 AM 0 stderr_20070309.log
14/03/2007 01:30 AM 0 stderr_20070314.log
22/03/2007 12:44 AM 0 stderr_20070322.log
23/03/2007 02:29 AM 0 stderr_20070323.log
07/03/2007 03:24 AM 0 stdout_20070307.log
09/03/2007 12:05 AM 0 stdout_20070309.log
14/03/2007 01:30 AM 0 stdout_20070314.log
22/03/2007 12:44 AM 0 stdout_20070322.log
23/03/2007 02:29 AM 874 stdout_20070323.log
41 File(s) 41,150 bytes
2 Dir(s) 36,205,051,904 bytes free

C:\ProgramInstall\Apache Software Foundation\Tomcat 6.0\logs>
Miguel Enriquez
Ranch Hand

Joined: Mar 13, 2004
Posts: 94
any notes:

display
the table with 2 clouns with titles:

Last Name
First Name

the user and password its correctly (i tested on a Sql explorer in eclipse)

thanks
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

By default stdout.txt I think, unless you have configured Tomcat to use something different. See this.
[ March 23, 2007: Message edited by: Paul Sturrock ]
Miguel Enriquez
Ranch Hand

Joined: Mar 13, 2004
Posts: 94
strange i installed tomcat, as normal. next next next, only changed, the port to 9090, and don have stdout.txt


C:\ProgramInstall\Apache Software Foundation>dir std*.txt /s/p
Volume in drive C has no label.
Volume Serial Number is 5A0A-0BB5
File Not Found

C:\ProgramInstall\Apache Software Foundation>

mmmm

checking the other tip....

thanks
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Sorry, that should be stout.log.
Miguel Enriquez
Ranch Hand

Joined: Mar 13, 2004
Posts: 94
C:\ProgramInstall>dir st*.log /s/p
Volume in drive C has no label.
Volume Serial Number is 5A0A-0BB5

Directory of C:\ProgramInstall\Apache Software Foundation\Tomcat 6.0\logs

07/03/2007 03:24 AM 0 stderr_20070307.log
09/03/2007 12:05 AM 0 stderr_20070309.log
14/03/2007 01:30 AM 0 stderr_20070314.log
22/03/2007 12:44 AM 0 stderr_20070322.log
23/03/2007 02:29 AM 0 stderr_20070323.log
07/03/2007 03:24 AM 0 stdout_20070307.log
09/03/2007 12:05 AM 0 stdout_20070309.log
14/03/2007 01:30 AM 0 stdout_20070314.log
22/03/2007 12:44 AM 0 stdout_20070322.log
23/03/2007 02:29 AM 874 stdout_20070323.log
10 File(s) 874 bytes

Total Files Listed:
10 File(s) 874 bytes
0 Dir(s) 34,986,553,344 bytes free

C:\ProgramInstall>cd "Apache Software Foundation"

C:\ProgramInstall\Apache Software Foundation>cd "Tomcat 6.0"

C:\ProgramInstall\Apache Software Foundation\Tomcat 6.0>cd logs


C:\ProgramInstall\Apache Software Foundation\Tomcat 6.0\logs>notepad stdout_2007
0323.log


java.util.logging.ErrorManager: 1
java.lang.NullPointerException
at org.apache.juli.FileHandler.publish(FileHandler.java:137)
at java.util.logging.Logger.log(Unknown Source)
at java.util.logging.Logger.doLog(Unknown Source)
at java.util.logging.Logger.logp(Unknown Source)
at org.apache.juli.logging.DirectJDKLog.log(DirectJDKLog.java:165)
at org.apache.juli.logging.DirectJDKLog.info(DirectJDKLog.java:115)
at org.apache.coyote.http11.Http11Protocol.pause(Http11Protocol.java:219)
at org.apache.catalina.connector.Connector.pause(Connector.java:1074)
at org.apache.catalina.core.StandardService.stop(StandardService.java:489)
at org.apache.catalina.core.StandardServer.stop(StandardServer.java:744)
at org.apache.catalina.startup.Catalina.stop(Catalina.java:602)
at org.apache.catalina.startup.Catalina$CatalinaShutdownHook.run(Catalina.java:645)



any advice ? thanks
Joan Horta Tosas
Ranch Hand

Joined: Feb 01, 2007
Posts: 59
At first sight, you need to put an "?" before the username in the connection URL.
Miguel Enriquez
Ranch Hand

Joined: Mar 13, 2004
Posts: 94
added the "?" before user

Class.forName("org.gjt.mm.mysql.Driver").newInstance();
conn =DriverManager.getConnection("jdbc:mysql://localhost/embarques" +
"?user=embarques&password=embarquesX2006X");

but only display:



Last Name First Name
Ooops, something bad happened:


thanks
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18889
    
    8

And the stack trace?
Miguel Enriquez
Ranch Hand

Joined: Mar 13, 2004
Posts: 94
these code:

<HTML>
<HEAD><TITLE>Employee List</TITLE></HEAD>
<BODY>
<%@ page import="java.sql.*" %>
<TABLE BORDER=1 width="75%">
<TR><TH>Last Name</TH><TH>First Name</TH></TR>
<%
Connection conn = null;
Statement st = null;
ResultSet rs = null;
try {%>
Realizando conexion ...
<%
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
conn =DriverManager.getConnection("jdbc:mysql://localhost/embarques" +
"?user=embarques&password=embarquesX2006X");%>
Conexion Establecida!!
<%
st = conn.createStatement();
rs = st.executeQuery("select * from tlogin");
rs.first();
while(rs.next()) {
%>
<TR><TD><%= rs.getString("iloginid") %></TD>
<TD><%= rs.getString("cloginusua") %></TD></TR>
<%
}
%>
</TABLE>
<%
} catch (Exception ex) {
ex.printStackTrace();
%>
</TABLE>
Ooops, something bad happened:
<%

} finally {
if (rs != null) rs.close();
if (st != null) st.close();
if (conn != null) conn.close();
}
%>
</BODY>
</HTML>



display:


Realizando conexion ...
Last Name First Name
Ooops, something bad happened:

i think my error is in line:
Class.forName("org.gjt.mm.mysql.Driver").newInstance();


any advice?

what about stack?

thanks
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

The stack trace will tell you why this is failing. You need to look at it. If you don't understand it post it here and someone will help.
 
 
subject: JSP + Mysql connection