主题:struts从字符串转换为 datetime 时发生语法错误
jinjzk
[专家分:0] 发布于 2007-11-05 16:46:00
问题很奇怪,按了搜索,在tomcat下面都可以把想要得结果输出来,可是大概过了几分钟就出现了从字符串转换为 datetime 时发生语法错误这个错误,数据库是sql,有哪位大哥碰到过这个问题
search76.jsp
<%@ page language="java" pageEncoding="gb2312"%>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %>
<html>
<head>
<title>aswwd</title>
<link rel="stylesheet" href="images/css.css" type="text/css" media="screen">
</head>
<body>
<html:form action="/search76">
<table width="773" border="0" align="center" cellpadding="0" cellspacing="0" class="zhengw">
<tr class="zhengwen">
<td width="26%"><div align="center" class="zhengw">
<label></label>
<div align="left">地区</div>
</div></td>
<td width="8%"> </td>
<td width="10%"><div align="center">开始时间</div></td>
<td width="13%"><div align="center">
<input class="input" onClick="fPopCalendar(regdate,regdate);return false" type="text" name="regdate" size="12">
</div></td>
<td width="24%"><p>
<label>
<select name="smini" size="1" class="bdtj3" id="smini">
<option value="9" selected>9</option>
<%
int i=0;
for(i=0;i<=23;i++){
out.write("<option value=\"" + i + "\">" + i + "</option>");
}
%>
</select>
点 </label>
</p></td>
<td width="19%"> </td>
</tr>
<tr class="zhengwen">
<td><div align="center">
<label></label>
<select name="sheng" size="1" class="bdtj3" id="sheng">
<option value="AllCountry" selected>全国</option>
<option value="安徽">安徽</option>
<option value="重庆">重庆</option>
<option value="湖北">湖北</option>
<option value="吉林">吉林</option>
<option value="内蒙古">内蒙古</option>
<option value="宁夏">宁夏</option>
<option value="山西">山西</option>
<option value="福建">福建</option>
<option value="浙江">浙江</option>
<option value="辽宁">辽宁</option>
<option value="河南">河南</option>
<option value="甘肃">甘肃</option>
<option value="新疆">新疆</option>
<option value="黑龙江">黑龙江</option>
<option value="青海">青海</option>
<option value="河北">河北</option>
<option value="四川">四川</option>
<option value="江西">江西</option>
<option value="天津">天津</option>
<option value="江苏">江苏</option>
<option value="西藏">西藏</option>
<option value="海南">海南</option>
<option value="贵州">贵州</option>
<option value="广东">广东</option>
<option value="湖南">湖南</option>
<option value="山东">山东</option>
<option value="上海">上海</option>
<option value="陕西">陕西</option>
<option value="云南">云南</option>
<option value="广西">广西</option>
</select>
</div></td>
<td> </td>
<td><div align="center">结束时间</div></td>
<td><div align="center">
<input class="input" onClick="fPopCalendar(regdate2,regdate2);return false" type="text" name="regdate2" size="12">
</div></td>
<td><label>
<select name="emini" size="1" class="bdtj3" id="emini">
<option value="9" selected>9</option>
<%
for(i=0;i<=23;i++){
out.write("<option value=\"" + i + "\">" + i + "</option>");
}
%>
</select>
点 </label></td>
<td> </td>
</tr>
<tr class="zhengwen">
<td><div align="right"></div></td>
<td colspan="3"><div align="center"></div></td>
<td> </td>
<td> </td>
</tr>
<tr class="zhengwen1">
<td><div align="right"></div></td>
<td colspan="3"><div align="center"></div></td>
<td> </td>
<td><input type="submit" name="Submit" onClick="submitForm()" value="开始搜索" class="bdtj" align="middle"></td>
</tr>
</table>
</html:form>
</body>
</html>
struts-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.3//EN" "http://struts.apache.org/dtds/struts-config_1_3.dtd">
<struts-config>
<form-beans >
<form-bean name="loginForm" type="com.LoginForm" />
<form-bean name="search76Form" type="com.Search76Form" />
</form-beans>
<global-exceptions />
<global-forwards />
<action-mappings >
<action
attribute="loginForm"
input="/login.jsp"
name="loginForm"
path="/login"
scope="request"
type="com.LoginAction">
<forward name="Success" path="/main.jsp" />
<forward name="Fail" path="/register.jsp" />
</action>
<action path="/AdminLoginOut" type="com.AdminLoginOut" >
<forward name="adminIndex" path="/login.jsp" />
</action>
<action
attribute="search76Form"
input="/search76.jsp"
name="search76Form"
path="/search76"
scope="request"
type="com.Search76Action">
<forward name="search76Success" path="/right.jsp" />
<forward name="search76Fail" path="/register.jsp" />
</action>
</action-mappings>
<message-resources parameter="com.ApplicationResources" />
</struts-config>
[color=FF0000]xml[/color][color=FF0000]jsp[/color][color=C0C0C0]java[/color]
回复列表 (共7个回复)
沙发
jinjzk [专家分:0] 发布于 2007-11-05 16:50:00
Search76Action.java
/*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package com;
import java.util.ArrayList;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
/**
* MyEclipse Struts
* Creation date: 11-01-2007
*
* XDoclet definition:
* @struts.action path="/search76" name="search76Form" input="/search76.jsp" scope="request" validate="true"
*/
public class Search76Action extends Action {
/*
* Generated Methods
*/
/**
* Method execute
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
*/
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
Search76Form search76Form = (Search76Form) form;// TODO Auto-generated method stub
String sheng = search76Form.getSheng();
String emini = search76Form.getEmini();
String smini = search76Form.getSmini();
String regdate2 = search76Form.getRegdate2();
String regdate = search76Form.getRegdate();
String stime=regdate+" "+smini+":00:00";
String etime=regdate2+" "+emini+":00:00";
//生成一个ArrayList对象,并把用户名和密码的值存入该对象中
ArrayList arr = new ArrayList();
arr.add(sheng);
arr.add(stime);
arr.add(etime);
String prompt=null;
//调用模型组件Search76Handler
if("AllCountry".equals(sheng)){
Search76Handler Search76 = new Search76Handler();
boolean mark = Search76.checkAllCountry(arr);
if(mark) prompt = "search76Success";
else prompt = "search76Fail";
//System.out.println(sheng);
System.out.println(prompt);
}else{
Search76Handler Search76 = new Search76Handler();
boolean mark = Search76.checkSheng(arr);
if(mark) prompt = "search76Success";
else prompt = "search76Fail";
//System.out.println(sheng);
System.out.println(prompt);
}
return mapping.findForward(prompt);
}
}
板凳
jinjzk [专家分:0] 发布于 2007-11-05 16:50:00
Search76Form.java
/*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package com;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
/**
* MyEclipse Struts
* Creation date: 11-01-2007
*
* XDoclet definition:
* @struts.form name="search76Form"
*/
public class Search76Form extends ActionForm {
/*
* Generated fields
*/
/** sheng property */
private String sheng;
/** emini property */
private String emini;
/** smini property */
private String smini;
/** regdate2 property */
private String regdate2;
/** regdate property */
private String regdate;
/*
* Generated Methods
*/
/**
* Method validate
* @param mapping
* @param request
* @return ActionErrors
*/
public ActionErrors validate(ActionMapping mapping,
HttpServletRequest request) {
// TODO Auto-generated method stub
return null;
}
/**
* Method reset
* @param mapping
* @param request
*/
public void reset(ActionMapping mapping, HttpServletRequest request) {
// TODO Auto-generated method stub
}
/**
* Returns the sheng.
* @return String
*/
public String getSheng() {
return sheng;
}
/**
* Set the sheng.
* @param sheng The sheng to set
*/
public void setSheng(String sheng) {
this.sheng = sheng;
}
/**
* Returns the emini.
* @return String
*/
public String getEmini() {
return emini;
}
/**
* Set the emini.
* @param emini The emini to set
*/
public void setEmini(String emini) {
this.emini = emini;
}
/**
* Returns the smini.
* @return String
*/
public String getSmini() {
return smini;
}
/**
* Set the smini.
* @param smini The smini to set
*/
public void setSmini(String smini) {
this.smini = smini;
}
/**
* Returns the regdate2.
* @return String
*/
public String getRegdate2() {
return regdate2;
}
/**
* Set the regdate2.
* @param regdate2 The regdate2 to set
*/
public void setRegdate2(String regdate2) {
this.regdate2 = regdate2;
}
/**
* Returns the regdate.
* @return String
*/
public String getRegdate() {
return regdate;
}
/**
* Set the regdate.
* @param regdate The regdate to set
*/
public void setRegdate(String regdate) {
this.regdate = regdate;
}
}
3 楼
jinjzk [专家分:0] 发布于 2007-11-05 16:52:00
Search76Handler.java
package com;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
public class Search76Handler {
Connection conn;
PreparedStatement ps;
ResultSet rs;
String sql3330="";
String sql3331="";
String sql3332="";
String sql3333="";
String sql4330="";
String sql4331="";
String sql4332="";
String num3330="";//总的通话分钟
String num3331="";
String num3332="";
String num3333="";
String num4330="";
String num4331="";
String num4332="";
float num3330f=0;
float num3331f=0;
float num3332f=0;
float num3333f=0;
float num4330f=0;
float num4331f=0;
float num4332f=0;
public boolean checkAllCountry(ArrayList arr) {
//String stime = (String)arr.get(1);
//String etime = (String)arr.get(2);
ArrayList list = new ArrayList();
conn = DBPool.getConnection();
try {
sql3330="SELECT SUM(CEILING(DATEDIFF(s, StartTime, EndTime) / 60) + 1) AS SUM3330 FROM xgsx_Call_Log where StartTime>convert(datetime,'"+(String)arr.get(1)+"') and EndTime<convert(datetime,'"+(String)arr.get(2)+"') and calleeid='101763330' and DATEDIFF(s,StartTime,EndTime)>15 and DATEDIFF(s,StartTime,EndTime)<2400 GROUP BY calleeid";
System.out.println(sql3330);
ps = conn.prepareStatement(sql3330);
rs = ps.executeQuery();
if(rs.next()){
num3330=rs.getString("SUM3330");
}else{
num3330="0";
}
num3330f=Float.parseFloat(num3330);
System.out.println(num3330f);
sql3331="SELECT SUM(CEILING(DATEDIFF(s, StartTime, EndTime) / 60) + 1) AS SUM3331 FROM xgsx_Call_Log where StartTime>convert(datetime,'"+(String)arr.get(1)+"') and EndTime<convert(datetime,'"+(String)arr.get(2)+"') and calleeid='101763331' and DATEDIFF(s,StartTime,EndTime)>15 and DATEDIFF(s,StartTime,EndTime)<2400 GROUP BY calleeid";
ps = conn.prepareStatement(sql3331);
rs = ps.executeQuery();
if(rs.next()){
num3331=rs.getString("SUM3331");
}else{
num3331="0";
}
num3331f=Float.parseFloat(num3331);
System.out.println(num3331f);
sql3332="SELECT SUM(CEILING(DATEDIFF(s, StartTime, EndTime) / 60) + 1) AS SUM3332 FROM xgsx_Call_Log where StartTime>convert(datetime,'"+(String)arr.get(1)+"') and EndTime<convert(datetime,'"+(String)arr.get(2)+"') and calleeid='101763332' and DATEDIFF(s,StartTime,EndTime)>15 and DATEDIFF(s,StartTime,EndTime)<2400 GROUP BY calleeid";
ps = conn.prepareStatement(sql3332);
rs = ps.executeQuery();
if(rs.next()){
num3332=rs.getString("SUM3332");
}else{
num3332="0";
}
sql3333="SELECT SUM(CEILING(DATEDIFF(s, StartTime, EndTime) / 60) + 1) AS SUM3333 FROM xgsx_Call_Log where StartTime>convert(datetime,'"+(String)arr.get(1)+"') and EndTime<convert(datetime,'"+(String)arr.get(2)+"') and calleeid='101763333' and DATEDIFF(s,StartTime,EndTime)>15 and DATEDIFF(s,StartTime,EndTime)<2400 GROUP BY calleeid";
ps = conn.prepareStatement(sql3333);
rs = ps.executeQuery();
if(rs.next()){
num3333=rs.getString("SUM3333");
}else{
num3333="0";
}
num3333f=Float.parseFloat(num3333);
4 楼
jinjzk [专家分:0] 发布于 2007-11-05 16:52:00
sql4330="SELECT SUM(CEILING(DATEDIFF(s, StartTime, EndTime) / 60) + 1) AS SUM4330 FROM xgsx_Call_Log where StartTime>convert(datetime,'"+(String)arr.get(1)+"') and EndTime<convert(datetime,'"+(String)arr.get(2)+"') and calleeid='101764330' and DATEDIFF(s,StartTime,EndTime)>15 and DATEDIFF(s,StartTime,EndTime)<1440 GROUP BY calleeid";
ps = conn.prepareStatement(sql4330);
rs = ps.executeQuery();
if(rs.next()){
num4330=rs.getString("SUM4330");
}else{
num4330="0";
}
num4330f=Float.parseFloat(num4330);
sql4331="SELECT SUM(CEILING(DATEDIFF(s, StartTime, EndTime) / 60) + 1) AS SUM4331 FROM xgsx_Call_Log where StartTime>convert(datetime,'"+(String)arr.get(1)+"') and EndTime<convert(datetime,'"+(String)arr.get(2)+"') and calleeid='101764331' and DATEDIFF(s,StartTime,EndTime)>15 and DATEDIFF(s,StartTime,EndTime)<1440 GROUP BY calleeid";
ps = conn.prepareStatement(sql4331);
rs = ps.executeQuery();
if(rs.next()){
num4331=rs.getString("SUM4331");
}else{
num4331="0";
}
num4331f=Float.parseFloat(num4331);
sql4332="SELECT SUM(CEILING(DATEDIFF(s, StartTime, EndTime) / 60) + 1) AS SUM4332 FROM xgsx_Call_Log where StartTime>convert(datetime,'"+(String)arr.get(1)+"') and EndTime<convert(datetime,'"+(String)arr.get(2)+"') and calleeid='101764332' and DATEDIFF(s,StartTime,EndTime)>15 and DATEDIFF(s,StartTime,EndTime)<1440 GROUP BY calleeid";
ps = conn.prepareStatement(sql4332);
rs = ps.executeQuery();
if(rs.next()){
num4332=rs.getString("SUM4332");
}else{
num4332="0";
}
num4332f=Float.parseFloat(num4332);
list.add(num3330f);
list.add(num3331f);
list.add(num3332f);
list.add(num3333f);
list.add(num4330f);
list.add(num4331f);
list.add(num4332f);
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
5 楼
jinjzk [专家分:0] 发布于 2007-11-05 16:53:00
sql4330="SELECT SUM(CEILING(DATEDIFF(s, StartTime, EndTime) / 60) + 1) AS SUM4330 FROM xgsx_Call_Log where StartTime>convert(datetime,'"+(String)arr.get(1)+"') and EndTime<convert(datetime,'"+(String)arr.get(2)+"') and calleeid='101764330' and DATEDIFF(s,StartTime,EndTime)>15 and DATEDIFF(s,StartTime,EndTime)<1440 GROUP BY calleeid";
ps = conn.prepareStatement(sql4330);
rs = ps.executeQuery();
if(rs.next()){
num4330=rs.getString("SUM4330");
}else{
num4330="0";
}
num4330f=Float.parseFloat(num4330);
sql4331="SELECT SUM(CEILING(DATEDIFF(s, StartTime, EndTime) / 60) + 1) AS SUM4331 FROM xgsx_Call_Log where StartTime>convert(datetime,'"+(String)arr.get(1)+"') and EndTime<convert(datetime,'"+(String)arr.get(2)+"') and calleeid='101764331' and DATEDIFF(s,StartTime,EndTime)>15 and DATEDIFF(s,StartTime,EndTime)<1440 GROUP BY calleeid";
ps = conn.prepareStatement(sql4331);
rs = ps.executeQuery();
if(rs.next()){
num4331=rs.getString("SUM4331");
}else{
num4331="0";
}
num4331f=Float.parseFloat(num4331);
sql4332="SELECT SUM(CEILING(DATEDIFF(s, StartTime, EndTime) / 60) + 1) AS SUM4332 FROM xgsx_Call_Log where StartTime>convert(datetime,'"+(String)arr.get(1)+"') and EndTime<convert(datetime,'"+(String)arr.get(2)+"') and calleeid='101764332' and DATEDIFF(s,StartTime,EndTime)>15 and DATEDIFF(s,StartTime,EndTime)<1440 GROUP BY calleeid";
ps = conn.prepareStatement(sql4332);
rs = ps.executeQuery();
if(rs.next()){
num4332=rs.getString("SUM4332");
}else{
num4332="0";
}
num4332f=Float.parseFloat(num4332);
list.add(num3330f);
list.add(num3331f);
list.add(num3332f);
list.add(num3333f);
list.add(num4330f);
list.add(num4331f);
list.add(num4332f);
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
6 楼
jinjzk [专家分:0] 发布于 2007-11-05 16:54:00
public boolean checkSheng(ArrayList arr){
String sheng = (String)arr.get(0);
System.out.println(sheng);
//String stime = (String)arr.get(1);
//String etime = (String)arr.get(2);
ArrayList list = new ArrayList();
conn = DBPool.getConnection();
try {
sql3330="SELECT SUM(CEILING(DATEDIFF(s, StartTime, EndTime) / 60) + 1) AS SUM3330 FROM xgsx_Call_Log where StartTime>convert(datetime,'"+(String)arr.get(1)+"') and EndTime<convert(datetime,'"+(String)arr.get(2)+"') and calleeid='101763330' and DATEDIFF(s,StartTime,EndTime)>15 and DATEDIFF(s,StartTime,EndTime)<2400 and left(callerno,7) in ((select telearea from Phone_CHINA where province='"+sheng+"')) GROUP BY calleeid";
ps = conn.prepareStatement(sql3330);
rs = ps.executeQuery();
if(rs.next()){
num3330=rs.getString("SUM3330");
}else{
num3330="0";
}
num3330f=Float.parseFloat(num3330);
System.out.println(num3330f);
sql3331="SELECT SUM(CEILING(DATEDIFF(s, StartTime, EndTime) / 60) + 1) AS SUM3331 FROM xgsx_Call_Log where StartTime>convert(datetime,'"+(String)arr.get(1)+"') and EndTime<convert(datetime,'"+(String)arr.get(2)+"') and calleeid='101763331' and DATEDIFF(s,StartTime,EndTime)>15 and DATEDIFF(s,StartTime,EndTime)<2400 and left(callerno,7) in ((select telearea from Phone_CHINA where province='"+sheng+"')) GROUP BY calleeid";
ps = conn.prepareStatement(sql3331);
rs = ps.executeQuery();
if(rs.next()){
num3331=rs.getString("SUM3331");
}else{
num3331="0";
}
num3331f=Float.parseFloat(num3331);
sql3332="SELECT SUM(CEILING(DATEDIFF(s, StartTime, EndTime) / 60) + 1) AS SUM3332 FROM xgsx_Call_Log where StartTime>convert(datetime,'"+(String)arr.get(1)+"') and EndTime<convert(datetime,'"+(String)arr.get(2)+"') and calleeid='101763332' and DATEDIFF(s,StartTime,EndTime)>15 and DATEDIFF(s,StartTime,EndTime)<2400 and left(callerno,7) in ((select telearea from Phone_CHINA where province='"+sheng+"')) GROUP BY calleeid";
ps = conn.prepareStatement(sql3332);
rs = ps.executeQuery();
if(rs.next()){
num3332=rs.getString("SUM3332");
}else{
num3332="0";
}
num3332f=Float.parseFloat(num3332);
sql3333="SELECT SUM(CEILING(DATEDIFF(s, StartTime, EndTime) / 60) + 1) AS SUM3333 FROM xgsx_Call_Log where StartTime>convert(datetime,'"+(String)arr.get(1)+"') and EndTime<convert(datetime,'"+(String)arr.get(2)+"') and calleeid='101763333' and DATEDIFF(s,StartTime,EndTime)>15 and DATEDIFF(s,StartTime,EndTime)<2400 and left(callerno,7) in ((select telearea from Phone_CHINA where province='"+sheng+"')) GROUP BY calleeid";
ps = conn.prepareStatement(sql3333);
rs = ps.executeQuery();
if(rs.next()){
num3333=rs.getString("SUM3333");
}else{
num3333="0";
}
num3333f=Float.parseFloat(num3333);
7 楼
jinjzk [专家分:0] 发布于 2007-11-05 16:54:00
sql4330="SELECT SUM(CEILING(DATEDIFF(s, StartTime, EndTime) / 60) + 1) AS SUM4330 FROM xgsx_Call_Log where StartTime>convert(datetime,'"+(String)arr.get(1)+"') and EndTime<convert(datetime,'"+(String)arr.get(2)+"') and calleeid='101764330' and DATEDIFF(s,StartTime,EndTime)>15 and DATEDIFF(s,StartTime,EndTime)<1440 and left(callerno,7) in ((select telearea from Phone_CHINA where province='"+sheng+"')) GROUP BY calleeid";
ps = conn.prepareStatement(sql4330);
rs = ps.executeQuery();
if(rs.next()){
num4330=rs.getString("SUM4330");
}else{
num4330="0";
}
num4330f=Float.parseFloat(num4330);
sql4331="SELECT SUM(CEILING(DATEDIFF(s, StartTime, EndTime) / 60) + 1) AS SUM4331 FROM xgsx_Call_Log where StartTime>convert(datetime,'"+(String)arr.get(1)+"') and EndTime<convert(datetime,'"+(String)arr.get(2)+"') and calleeid='101764331' and DATEDIFF(s,StartTime,EndTime)>15 and DATEDIFF(s,StartTime,EndTime)<1440 and left(callerno,7) in ((select telearea from Phone_CHINA where province='"+sheng+"')) GROUP BY calleeid";
ps = conn.prepareStatement(sql4331);
rs = ps.executeQuery();
if(rs.next()){
num4331=rs.getString("SUM4331");
}else{
num4331="0";
}
num4331f=Float.parseFloat(num4331);
sql4332="SELECT SUM(CEILING(DATEDIFF(s, StartTime, EndTime) / 60) + 1) AS SUM4332 FROM xgsx_Call_Log where StartTime>convert(datetime,'"+(String)arr.get(1)+"') and EndTime<convert(datetime,'"+(String)arr.get(2)+"') and calleeid='101764332' and DATEDIFF(s,StartTime,EndTime)>15 and DATEDIFF(s,StartTime,EndTime)<1440 and left(callerno,7) in ((select telearea from Phone_CHINA where province='"+sheng+"')) GROUP BY calleeid";
ps = conn.prepareStatement(sql4332);
rs = ps.executeQuery();
if(rs.next()){
num4332=rs.getString("SUM4332");
}else{
num4332="0";
}
num4332f=Float.parseFloat(num4332);
list.add(num3330f);
list.add(num3331f);
list.add(num3332f);
list.add(num3333f);
list.add(num4330f);
list.add(num4331f);
list.add(num4332f);
return true;
}catch (Exception e) {
e.printStackTrace();
return false;
}
}
}
[color=FF0000]xml[/color][color=FF0000]jsp[/color][color=C0C0C0]java[/color]
我来回复