java怎么取出mysql中datetime类型数据字段

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java怎么取出mysql中datetime类型数据字段相关的知识,希望对你有一定的参考价值。

参考技术A java 实体可以用String类型接收。持久层你用什么框架了么?如果用的jdbc ,获取值可以直接用xxxx.getString("对应字段")试一试

mysql中datetime类型字段为默认值0000-00-00 00:00:00怎么取出来

今天遇到了这个问题,rs.getString(4)是datetime类型,而且是默认值报错:然后网上搜素了一下解决方案如下:原来是jdbc连接的问题改成这样jdbc:mysql://localhost:3306/brilliant?user=conglin&password=conglin&useUnicode=true&characterEncoding=gbk&zeroDateTimeBehavior=convertToNullreliably in Java.Connector/J 3.0.x always converted them to NULL when being read from a ResultSet.当这些值正在从ResultSet容器中读取时候,Connector/J 3.0.x 一直把他们转换为NULL值。Connector/J 3.1 throws an exception by default when these values are encountered as this is the most correct behavior according to the JDBC and SQL standards.依照JDBC和SQL的标准这些值碰到的最正确的处理方式就是在缺省情况下产生异常This behavior can be modified using the zeroDateTimeBehavior configuration property. The allowable values are:JDBC允许用下列的值对zeroDateTimeBehavior 属性来设置这些处理方式,exception (the default), which throws an SQLException with an SQLState of S1009.设置为exception 异常(缺省)用一个SQLState的s1009错误号来抛出一个异常convertToNull, which returns NULL instead of the date.设置为convertToNull,用NULL值来代替这个日期类型 参考技术A 当你插入一条数据时,如果不填这个字段的值,该列自己会填写默认值。数据库存储的是数据,你应该取出来的是数据,而不是类型吧

以上是关于java怎么取出mysql中datetime类型数据字段的主要内容,如果未能解决你的问题,请参考以下文章

java怎么取出mysql中datetime类型数据字段

mysql中datetime类型字段为默认值0000-00-00 00:00:00怎么取出来

mysql中datetime类型字段为默认值0000-00-00 00:00:00怎么取出来

Java 如何存取MySQL datetime类型

从mysql中取出的时间为datetime类型,在页面显示却是object

java怎么使用日期格式化将时间插入mysql datetime数据类型中?