mysql中datetime类型字段为默认值0000-00-00 00:00:00怎么取出来
来源:互联网 发布:上海811所硕士待遇知乎 编辑:程序博客网 时间:2024/04/30 02:23
今天遇到了这个问题,
rs.getString(4)是datetime类型,而且是默认值
报错:
Cannot convert value '0000-00-00 00:00:00' from column 9 to TIMESTAMP.
然后网上搜素了一下解决方案如下:
原来是jdbc连接的问题
改成这样jdbc:mysql://localhost:3306/brilliant?user=conglin&password=conglin&useUnicode=true&characterEncoding=gbk&zeroDateTimeBehavior=convertToNull
Datetimes with all-zero components (0000-00-00 ...) — These values can not be represented 关于所有Datetime类型由0组成的数据,这些值不能在java中被可靠的表示
reliably 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值来代替这个日期类型
round, which rounds the date to the nearest closest value which is 0001-01-01.
设置为round,则围绕这个日期最接近的值(0001-01-01)来代替
原文解决方案地址http://topic.csdn.net/u/20080423/10/2d2288d4-00ae-4066-9e76-b6b843aa7d1a.html
- mysql中datetime类型字段为默认值0000-00-00 00:00:00怎么取出来
- mysql中datetime类型字段怎么取出来?
- mysql 数据库字段为datetime类型时默认值为:0000-00-00 00:00:00 查询时异常 java.sql.SQLException:Value '0000-00-00' can not be represented as java.sq
- 关于Java读取mysql中date类型字段默认值'0000-00-00'的问题
- Mysql 数据库date, datetime类型设置0000-00-00默认值报错问题
- Mysql 数据库date, datetime类型设置0000-00-00默认值报错问题
- sql2005 若字段定义的类型为datetime,插入为''(空),那么会默认值为1900-01-01 00:00:00.000
- mysql插入datetime默认值0000-00-00时报错
- Mysql中datetime默认值'0000-00-00 00:00:00'无法创建问题
- mysql中datetime默认值设置0000-00-00失败的问题
- MYSQL 5.5不支持字段类型为datetime且默认值为NOW()的建表语句
- MYSQL 5.5不支持字段类型为datetime且默认值为NOW()的建表语句
- mysql5.7 datetime 默认值为‘0000-00-00 00:00:00'值无法创建问题解决
- mysql数据库设置datetime类型 字段的默认值为CURRENT_TIMESTAMP(6)时报错
- java的Timestamp时间插入mysql的datetime字段是0000-00-00 00:00:00
- js转换mysql中datetime日期格式为00-00-00 00:00:00
- 如何将java中Date存入mysql中的datetime中,字符串怎么转换为日期类型
- 如何将java中Date存入mysql中的datetime中,字符串怎么转换为日期类型
- hdu 4004 二分 过河
- #include <Windows.h> 和 <Winsock2.h>冲突的改进解决方案
- Android DialogPreference Issue
- 详解个人职业生涯规划
- 玩具总动员中英对白
- mysql中datetime类型字段为默认值0000-00-00 00:00:00怎么取出来
- 少有人走的路---心智成熟的旅程
- 关于宝宝培养的思考
- 1045 access denied for user 'root'@'localhost' using password yes
- 判断字符串是否对称
- Android播放GIF图片
- Android开发学习笔记(一)
- 游戏算法-洗扑克牌
- 游戏算法-生命游戏