Mysql 时间格式默认插入值为空时,会以'0000-00-00 00:00:00'填充,这时如果select时会抛出SQLExecption如下:

java.sql.SQLException: Value '0000-00-00 00:00:00' can not be represented as java.sql.Timestamp

解决方法如下:

方法一:jdbc的url加zeroDateTimeBehavior参数:

datasource.url=jdbc:mysql://localhost:3306/testdb?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true

zeroDateTimeBehavior=round是为了指定MySql中的DateTime字段默认值查询时的处理方式;默认是抛出异常,

(摘自:http://www.blogjava.net/hilor/articles/164814.html)

方法二:select 语句中做如下处理:

SELECT ID, IF(createDate='0000-00-00 00:00:00','null',createDate)createDate FROM T_DateTest;

这里将createDate格式转换为”null“展示,不再抛出SQLException。

Mysql 时间格式默认空串 '0000-00-00 00:00:00' select抛出异常的解决方法的更多相关文章

  1. mysql错误:The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement解决方法

    本文为大家讲解的是mysql错误:The MySQL server is running with the --skip-grant-tables option so it cannot execut ...

  2. mysql时间格式DATE_FORMAT()

    1.以下是mysql查询中用到的时间格式的转化形式例子:SELECT DATE_FORMAT(NOW(),'%Y-%m-%d') -- 2015-10-28 SELECT DATE_FORMAT(NO ...

  3. mysql 时间格式与日期格式转换,去除datetime中的具体时间

    DATE_FORMAT(`addtime`,'%Y-%m-%d')  时间格式转成字符串 time_format('1924-01-02', '%Y-%m-%d') 字符串转成时间格式 CONVERT ...

  4. MySQL 出现You can't specify target table for update in FROM clause错误解决方法

    MySQL出现You can’t specify target table for update in FROM clause 这个错误的意思是不能在同一个sql语句中,先select同一个表的某些值 ...

  5. MySql Host is blocked because of many connection errors; unblock with 'mysqladmin flush-hosts' 的解决方法

    解决方法如下:  方法 1.在线修改提高允许的max_connection_errors数量: A. 登录Mysql数据库查看max_connection_errors: mysql>show ...

  6. MySQL时间格式TIMESTAMP和DATETIME的区别

    时区,timestamp会跟随设置的时区变化而变化,而datetime保存的是绝对值不会变化 自动更新,insert.update数据时,可以设置timestamp列自动以当前时间(CURRENT_T ...

  7. mysql 时间格式转换

    1.varchar 转 datetime 格式 DATE_FORMAT(time,'%Y-%m-%d %H:%m:%s');   2.时间减去一小时 DATE_FORMAT(date_add(time ...

  8. MySQL时间格式转换

    1.时间转换成特定字符串 例:select DATE_FORMAT(now(),'%Y-%m-%d %H:%i::%s'); --> '2019-10-16 10:59::18' 2.一种字符串 ...

  9. MySQL时间格式转换函数

    MySQL DATE_FORMAT() 函数注:当前年份是2018-7-19 SELECT DATE_FORMAT(NOW(),'%Y')                                ...

随机推荐

  1. echarts饼图点击事件

    /** * 点击事件 */myChart2.on('click', function (param) { var index = param.dataIndex; alert(index);});

  2. CTF---安全杂项入门第二题 A记录

    A记录分值:20 来源: sammie 难度:中 参与人数:2255人 Get Flag:566人 答题人数:621人 解题通过率:91% 他在看什么视频,好像很好看,不知道是什么网站的. 还好我截取 ...

  3. Codeforces Round #411 (Div. 2)(A,B,C,D 四水题)

    A. Fake NP time limit per test:1 second memory limit per test:256 megabytes input:standard input out ...

  4. UVA 11039-Building designing【贪心+绝对值排序】

    UVA11039-Building designing Time limit: 3.000 seconds An architect wants to design a very high build ...

  5. Java学习之类的构建方法(函数)

    在学习类的部分时,建立一个对象是这样建立的:(假设Person是类)Person  p = new  Person():我一直很费解为何new后面是一个函数形式, 今天学完构建方法后,才恍然大悟,豁然 ...

  6. hdu_1042(模拟大数乘法)

    计算n! #include<cstring> #include<cstdio> using namespace std; ]; int main() { int n; whil ...

  7. 二叉排序树BST+求树深度算法

    #include "stdio.h" #include "malloc.h" typedef struct node { int key; struct nod ...

  8. js闭包的真正理解

    <高级程序设计>上,这样说:当在函数内部定义了其他函数时候,就创建了闭包.闭包有权访问包含函数内部的所有变量. 这个说的太晦涩了,而且我觉得很容易理解错,闭包就是一个嵌套函数嘛?但是我觉得 ...

  9. 自己编写JavaScript的sort函数

    在平常开发中我们经常会遇到对数组进行排序的场景,js给我们提供了sort方法可以对数组元素进行排序,默认是按ASCII字母表顺序排序,请看下面例子: var a = [1, 3, 2, 4];var ...

  10. html日历(2)

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...