当前位置: 代码迷 >> Java Web开发 >> 求教!有关Date begintime = rs.getDate ( "begintime" )的有关问题
  详细解决方案

求教!有关Date begintime = rs.getDate ( "begintime" )的有关问题

热度:742   发布时间:2016-04-17 10:42:13.0
求教!有关Date begintime = rs.getDate ( "begintime" )的问题
首先我是想实现修改的功能,后来显示出Value '0000-00-00' can not be represented as java.sql.Date这样一个问题,按照网上教的方法在连接数据库语句后面添加zeroDateTimeBehavior=convertToNull,结果所有date类型的值都为0000-00-00了,怎么办呢?其实不是很明白网上这个方法的用意,求指教!下面是修改页面和显示页面的代码:

update_cooperation.jsp:

<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<title>无标题文档</title>
</head>

<body>
<%
Class.forName("com.mysql.jdbc.Driver").newInstance();
String url= "jdbc:mysql://localhost:3306/graduationproject?user=root&password=123&useUnicode=true&characterEncoding=GB2312&zeroDateTimeBehavior=convertToNull";
Connection connection=DriverManager.getConnection(url); 
Statement statement = connection.createStatement();
String number=request.getParameter("number");
String sql="select * from cooperations where number='"+number+"'";
ResultSet rs = statement.executeQuery(sql);
%>
  <table width="1572">
  <tr>
  <th width="169" scope="col"> 起始时间</th>
  <th width="169" scope="col">结束时间</th>
  <th width="166" scope="col">物料</th>
  <th width="168" scope="col">项目编号</th>
  <th width="169" scope="col"> 项目名称</th>
  <th width="167" scope="col">ICP</th>
  <th width="168" scope="col"> 供应商名称</th>
  <th width="169" scope="col">合作价格</th>
  <th width="169" scope="col">状态</th>
  </tr>
</table>
<% while(rs.next()) {%>


<form id="form1" name="form1" method="post" action="deal_update_cooperation.jsp">
<table width="1698">
  <tr>
  <th width="168" height="49" scope="col">
  <div align="center">
  <input type="hidden" name="number" value="<%=request.getParameter("number")%>"/>
  <input type="text" name="begintime" value="<%=rs.getTime("begintime")%>" />
  &nbsp;</a></div></th>
  <th width="168" scope="col">
  <div align="center">
  <input type="text" name="endtime" value="<%=rs.getTime("endtime")%>" />
  &nbsp;</div></th>
  <th width="168" scope="col">
  <div align="center">
  <input type="text" name="material" value="<%=rs.getString("material")%>" />
  &nbsp;</div></th>
  <th width="168" scope="col"><div align="center">
  <input name="p_number" type="text" value="<%=rs.getString("p_number")%>" />
  &nbsp; </div></th>
  <th width="168" scope="col">
  相关解决方案