java rs.getdate()异常,rs.getdate

当前位置:我的异常网» 热门搜索 » 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是个啥意思;

文章评论

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值