当前位置:我的异常网» 热门搜索 » rs.getdate
rs.getdate
www.myexceptions.net 网友分享于:2013-08-17 搜索量:4次
场景:求教!有关Date begintime = rs.getDate ( "begintime" )的有关问题
求教!有关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:
无标题文档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);
%>
起始时间 | 结束时间 | 物料 | 项目编号 | 项目名称 | ICP | 供应商名称 | 合作价格 | 状态 |
---|
"/> " /> |
" /> |
" /> |
" /> |
" /> |
"/> |
" /> |
" /> |
" /> |
---|
cooperation_management.jsp
无标题文档Class.forName("com.mysql.jdbc.Driver").newInstance();
String url= "jdbc:mysql://localhost:3306/graduationproject?user=root&password=123&useUnicode=true&characterEncoding=GB2312";
Connection connection=DriverManager.getConnection(url);
Statement statement = connection.createStatement();
String sql="select * from cooperations";
ResultSet rs = statement.executeQuery(sql);
%>
起始时间 | 结束时间 | 物料 | 项目名称 | 供应商名称 | 合作价格 | 状态 |
---|
while(rs.next()) {
String number = rs.getString ( "number" );
Date begintime = rs.getDate ( "begintime" );
Date endtime = rs.getDate ( "endtime" );
String material = rs.getString ( "material" );
String projectname = rs.getString ( "projectname" );
String suppliername = rs.getString ( "suppliername" );
Integer price = rs.getInt ( "price" );
String situation = rs.getString ( "situation" );
%>
修改 |
---|
------解决方案--------------------
你把rs.getTime()改为rs.getDate();
如果要把日期按某种格式输出,用DateFormat;
------解决方案--------------------
如果是下面语句有问题:
Date begintime = rs.getDate ( "begintime" );
Date endtime = rs.getDate ( "endtime" );
你在保存日期值时不要保存什么0000-00-00;直接为NULL就是,
0000-00-00是个啥意思;
文章评论