randyzapata
asked on
JSP MySQL 500 error
Can someone help me fix this error.
HTTP Status 500 -
-------------------------- ---------- ---------- ---------- ---------- ---------- ----
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
javax.servlet.ServletExcep tion: Cannot convert value '0000-00-00 00:00:00' from column 10 to TIMESTAMP.
org.apache.jasper.runtime. PageContex tImpl.doHa ndlePageEx ception(Pa geContextI mpl.java:8 48)
org.apache.jasper.runtime. PageContex tImpl.hand lePageExce ption(Page ContextImp l.java:781 )
org.apache.jsp.search_jsp. _jspServic e(org.apac he.jsp.sea rch_jsp:15 5)
org.apache.jasper.runtime. HttpJspBas e.service( HttpJspBas e.java:97)
javax.servlet.http.HttpSer vlet.servi ce(HttpSer vlet.java: 802)
org.apache.jasper.servlet. JspServlet Wrapper.se rvice(JspS ervletWrap per.java:3 22)
org.apache.jasper.servlet. JspServlet .serviceJs pFile(JspS ervlet.jav a:291)
org.apache.jasper.servlet. JspServlet .service(J spServlet. java:241)
javax.servlet.http.HttpSer vlet.servi ce(HttpSer vlet.java: 802)
root cause
java.sql.SQLException: Cannot convert value '0000-00-00 00:00:00' from column 10 to TIMESTAMP.
com.mysql.jdbc.ResultSet.g etTimestam pFromStrin g(ResultSe t.java:636 8)
com.mysql.jdbc.ResultSet.g etStringIn ternal(Res ultSet.jav a:2162)
com.mysql.jdbc.ResultSet.g etString(R esultSet.j ava:2077)
com.mysql.jdbc.ResultSet.g etString(R esultSet.j ava:2195)
org.apache.jsp.search_jsp. _jspServic e(org.apac he.jsp.sea rch_jsp:12 7)
org.apache.jasper.runtime. HttpJspBas e.service( HttpJspBas e.java:97)
javax.servlet.http.HttpSer vlet.servi ce(HttpSer vlet.java: 802)
org.apache.jasper.servlet. JspServlet Wrapper.se rvice(JspS ervletWrap per.java:3 22)
org.apache.jasper.servlet. JspServlet .serviceJs pFile(JspS ervlet.jav a:291)
org.apache.jasper.servlet. JspServlet .service(J spServlet. java:241)
javax.servlet.http.HttpSer vlet.servi ce(HttpSer vlet.java: 802)
note The full stack trace of the root cause is available in the Apache Tomcat/5.5.9 logs.
************************** ***
CREATE TABLE logs (Counter int not null auto_increment,
primary key (Counter),
Entered TIMESTAMP,
Title VARCHAR (80),
Salutation VARCHAR (5),
INUM VARCHAR (50),
TrainerName VARCHAR (80),
logType VARCHAR (50),
logNumber VARCHAR (50),
Country VARCHAR (80),
StartTime DATETIME,
StopTime DATETIME,
ContactedName VARCHAR (80),
ContactedRelationship VARCHAR (30),
AdditionalInfo VARCHAR (255));
************************** *****
<%@ page language="java" import="java.sql.*" %>
<HTML>
<HEAD>
<TITLE>Trainer</TITLE>
<META http-equiv="UrlId" content="com.sun.sunit.sdl c.content. RegisterWe bPageInfo" >
<META http-equiv="content-type" content="text/html; charset=iso-8859-1">
<LINK title="JSCstyle" href="AdminScripts/jscdscs tyle.css" type="text/css" rel="Stylesheet">
<META content="MSHTML 6.00.2800.1498" name="GENERATOR"></HEAD>
<BODY bgColor="#ffffff" leftMargin="0" topMargin="0" rightMargin="0" marginwidth="0" marginheight="0">
<%
// define variables
String Counter;
String TIMESTAMP;
String Title;
String Salutation;
String INUM;
String TrainerName;
String logType;
String logNumber;
String Country;
String StartTime;
String StopTime;
String ContactedName;
String ContactedRelationship;
String AdditionalInfo;
%>
<SCRIPT src="" type="text/JavaScript"></S CRIPT>
<DIV class="vnv1" id="vnv1v0">
<DIV class="cornerTL">
<DIV class="cornerTR">
<DIV class="cornerBL">
<DIV class="cornerBR">
<DIV class="vnv1search"> < /DIV>
</DIV>
</DIV>
</DIV>
</DIV>
</DIV>
<DIV class="pagetitle">Trainer log Tracking System<SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman'; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA"></SPAN></DIV> <!-- END PAGETITLE ONE LINE --> <!-- BEGIN WRAPPER TABLE, 2 COLUMN, LEFT/MAIN -->
<TABLE height="608" cellSpacing="0" cellPadding="10" width="1375" border="0">
<TBODY>
<TR>
<TD vAlign="top" width="55" height="624"></TD>
<TD vAlign="top" width="789" height="624"><A name="skip2content"></A>
<!--START TABLE-->
<TABLE height="631" cellSpacing="0" cellPadding="0" width="596" border="0">
<TBODY>
<TR>
<TD class="black" width="737" height="321">
<%
Class.forName("org.gjt.mm. mysql.Driv er");
// pass database parameters to JDBC driver
Connection Conn = DriverManager.getConnectio n("jdbc:my sql://loca lhost:3306 /Trainer?u ser=root") ;
// query statement
Statement SQLStatement = Conn.createStatement();
// generate query
String Query = "SELECT Counter,TIMESTAMP,Title,Ti tle,Saluta tion,INUM, TrainerNam e,logType, logNumber, Country,St artTime,St opTime,Con tactedName ,Contacted Relationsh ip,Additio nalInfo FROM logs";
// get result
ResultSet SQLResult = SQLStatement.executeQuery( Query);
while(SQLResult.next())
{
Counter = SQLResult.getString("Count er");
TIMESTAMP = SQLResult.getString("TIMES TAMP");
Title = SQLResult.getString("Title ");
Salutation = SQLResult.getString("Salut ation");
INUM = SQLResult.getString("INUM" );
TrainerName = SQLResult.getString("Train erName");
logType = SQLResult.getString("logTy pe");
logNumber = SQLResult.getString("logNu mber");
Country = SQLResult.getString("Count ry");
StartTime = SQLResult.getString("Start Time");
StopTime = SQLResult.getString("StopT ime");
ContactedName = SQLResult.getString("Conta ctedName") ;
ContactedRelationship = SQLResult.getString("Conta ctedRelati onship");
AdditionalInfo = SQLResult.getString("Addit ionalInfo" );
out.println("<tr><td>" + Counter + "</td><td>" + TIMESTAMP + "</td><td>" + Title + "</td><td>" + Salutation + "</td><td>" + INUM + "</td><td>" + TrainerName + "</td><td>" + logType + "</td><td>" + logNumber + "</td><td>" + Country + "</td><td>" + StartTime + "</td><td>" + StopTime + "</td><td>" + ContactedName + "</td><td>" + ContactedRelationship + "</td><td>" + AdditionalInfo + "</td></tr>"); }
// close connection
SQLStatement.close();
Conn.close();
%>
</TD>
</TR>
</TBODY></TABLE>
</TD>
</TR>
</TBODY></TABLE>
</BODY>
</HTML>
HTTP Status 500 -
--------------------------
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
javax.servlet.ServletExcep
org.apache.jasper.runtime.
org.apache.jasper.runtime.
org.apache.jsp.search_jsp.
org.apache.jasper.runtime.
javax.servlet.http.HttpSer
org.apache.jasper.servlet.
org.apache.jasper.servlet.
org.apache.jasper.servlet.
javax.servlet.http.HttpSer
root cause
java.sql.SQLException: Cannot convert value '0000-00-00 00:00:00' from column 10 to TIMESTAMP.
com.mysql.jdbc.ResultSet.g
com.mysql.jdbc.ResultSet.g
com.mysql.jdbc.ResultSet.g
com.mysql.jdbc.ResultSet.g
org.apache.jsp.search_jsp.
org.apache.jasper.runtime.
javax.servlet.http.HttpSer
org.apache.jasper.servlet.
org.apache.jasper.servlet.
org.apache.jasper.servlet.
javax.servlet.http.HttpSer
note The full stack trace of the root cause is available in the Apache Tomcat/5.5.9 logs.
**************************
CREATE TABLE logs (Counter int not null auto_increment,
primary key (Counter),
Entered TIMESTAMP,
Title VARCHAR (80),
Salutation VARCHAR (5),
INUM VARCHAR (50),
TrainerName VARCHAR (80),
logType VARCHAR (50),
logNumber VARCHAR (50),
Country VARCHAR (80),
StartTime DATETIME,
StopTime DATETIME,
ContactedName VARCHAR (80),
ContactedRelationship VARCHAR (30),
AdditionalInfo VARCHAR (255));
**************************
<%@ page language="java" import="java.sql.*" %>
<HTML>
<HEAD>
<TITLE>Trainer</TITLE>
<META http-equiv="UrlId" content="com.sun.sunit.sdl
<META http-equiv="content-type" content="text/html; charset=iso-8859-1">
<LINK title="JSCstyle" href="AdminScripts/jscdscs
<META content="MSHTML 6.00.2800.1498" name="GENERATOR"></HEAD>
<BODY bgColor="#ffffff" leftMargin="0" topMargin="0" rightMargin="0" marginwidth="0" marginheight="0">
<%
// define variables
String Counter;
String TIMESTAMP;
String Title;
String Salutation;
String INUM;
String TrainerName;
String logType;
String logNumber;
String Country;
String StartTime;
String StopTime;
String ContactedName;
String ContactedRelationship;
String AdditionalInfo;
%>
<SCRIPT src="" type="text/JavaScript"></S
<DIV class="vnv1" id="vnv1v0">
<DIV class="cornerTL">
<DIV class="cornerTR">
<DIV class="cornerBL">
<DIV class="cornerBR">
<DIV class="vnv1search"> <
</DIV>
</DIV>
</DIV>
</DIV>
</DIV>
<DIV class="pagetitle">Trainer log Tracking System<SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman'; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA"></SPAN></DIV> <!-- END PAGETITLE ONE LINE --> <!-- BEGIN WRAPPER TABLE, 2 COLUMN, LEFT/MAIN -->
<TABLE height="608" cellSpacing="0" cellPadding="10" width="1375" border="0">
<TBODY>
<TR>
<TD vAlign="top" width="55" height="624"></TD>
<TD vAlign="top" width="789" height="624"><A name="skip2content"></A>
<!--START TABLE-->
<TABLE height="631" cellSpacing="0" cellPadding="0" width="596" border="0">
<TBODY>
<TR>
<TD class="black" width="737" height="321">
<%
Class.forName("org.gjt.mm.
// pass database parameters to JDBC driver
Connection Conn = DriverManager.getConnectio
// query statement
Statement SQLStatement = Conn.createStatement();
// generate query
String Query = "SELECT Counter,TIMESTAMP,Title,Ti
// get result
ResultSet SQLResult = SQLStatement.executeQuery(
while(SQLResult.next())
{
Counter = SQLResult.getString("Count
TIMESTAMP = SQLResult.getString("TIMES
Title = SQLResult.getString("Title
Salutation = SQLResult.getString("Salut
INUM = SQLResult.getString("INUM"
TrainerName = SQLResult.getString("Train
logType = SQLResult.getString("logTy
logNumber = SQLResult.getString("logNu
Country = SQLResult.getString("Count
StartTime = SQLResult.getString("Start
StopTime = SQLResult.getString("StopT
ContactedName = SQLResult.getString("Conta
ContactedRelationship = SQLResult.getString("Conta
AdditionalInfo = SQLResult.getString("Addit
out.println("<tr><td>" + Counter + "</td><td>" + TIMESTAMP + "</td><td>" + Title + "</td><td>" + Salutation + "</td><td>" + INUM + "</td><td>" + TrainerName + "</td><td>" + logType + "</td><td>" + logNumber + "</td><td>" + Country + "</td><td>" + StartTime + "</td><td>" + StopTime + "</td><td>" + ContactedName + "</td><td>" + ContactedRelationship + "</td><td>" + AdditionalInfo + "</td></tr>"); }
// close connection
SQLStatement.close();
Conn.close();
%>
</TD>
</TR>
</TBODY></TABLE>
</TD>
</TR>
</TBODY></TABLE>
</BODY>
</HTML>
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hiya :-) Didn't go away, but there were plenty of bbqs to attend, a new PDA to play with, and Big Brother to watch ;-) *blush*
Hope you had a cool bank holiday!
Roll on August ;-)
Hope you had a cool bank holiday!
Roll on August ;-)
ASKER
how would I do a null check? Can I still output the data if I have a null in the database. I am new to all this.
Thanks,
Randall
Thanks,
Randall
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
It's because you are trying to get everything as a String, no matter what it really is... The database is choking trying to convert a null DATETIME to a String (as bloodredsun said)
StartTime and StopTime will be NULL if they are NULL in the database...
StartTime and StopTime will be NULL if they are NULL in the database...
ASKER
Thank you so much for helping me out,
Randall
Randall
Glad I could help :-)
Good luck with it all :-)
Good luck with it all :-)
Errr...shouldn't that be:
String Query = "SELECT Counter,Entered,Title,Titl
ie: Enterered, not TIMESTAMP
Why are you using getString() for everything too?
I guess it would work, but you'll be stuck if you want to format anything...
Tim