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

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抛出异常的解决方法

时间: 2024-08-03 19:28:11

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

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

Mysql关系型数据库管理系统 MySQL是一个开放源码的小型关联式数据库管理系统,开发者为瑞典MySQL AB公司.MySQL被广泛地应用在Internet上的中小型网站中.由于其体积小.速度快.总体拥有成本低,尤其是开放源码这一特点,许多中小型网站为了降低网站总体拥有成本而选择了MySQL作为网站数据库. 本文为大家讲解的是mysql错误:The MySQL server is running with the --skip-grant-tables option so it cannot

mysql 数据库数据迁移 The user specified as a definer ('root'@'%') does not exist 解决方法

从一个数据库数据迁移到本地localhost 程序在调用到数据库的视图时报错,直接在数据库中打开视图时也报错,类似: mysql 1449 : The user specified as a definer ('montor'@'%') does not exist 经查,是权限问题,解决办法: 运行:grant all privileges on *.* to [email protected]"%" identified by "."; 之后打开视图时便不会报错

连接mysql报错java.sql.SQLException: The server time zone value '?й???????' is unrecognized...解决方法

报错内容: java.sql.SQLException: The server time zone value '?й???????' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time

MySQL时间格式转换函数

MySQL DATE_FORMAT() 函数注:当前年份是2018-7-19 SELECT DATE_FORMAT(NOW(),'%Y')                                  YEAR 输出结果:2018 SELECT DATE_FORMAT(NOW(),'%y')                                   YEAR 输出结果:18 SELECT DATE_FORMAT(NOW(),'%m')                       

mysql中You can’t specify target table for update in FROM clause错误解决方法

mysql中You can't specify target table for update in FROM clause错误的意思是说,不能先select出同一表中的某些值,再update这个表(在同一语句中). 例如下面这个sql: 1 delete from tbl where id in 2 ( 3 select max(id) from tbl a where EXISTS 4 ( 5 select 1 from tbl b where a.tac=b.tac group by ta

iOS开发之时间格式的转化

在开发iOS程序时,有时候需要将时间格式调整成自己希望的格式,这个时候我们可以用NSDateFormatter类来处理. 例如:如何将格式为“12-May-14 05.08.02.000000 PM”的时间转化成“2014/05/12 5:08:02”,下面是具体实现代码: NSString* timeStr = @"12-May-14 05.08.02.000000 PM"; NSDateFormatter *formatter = [[NSDateFormatter alloc]

MySQL 8.0 Public Key Retrieval is not allowed 错误的解决方法

在跟着视频练习时,又遇到一个问题,解决方案如下: 在使用 MySQL 8.0 时重启应用后提示 com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Public Key Retrieval is not allowed 最简单的解决方法是在连接后面添加 allowPublicKeyRetrieval=true 文档中(https://mysql-net.github.io/MySqlConnector/con

黄聪:MySql Host is blocked because of many connection errors; unblock with 'mysqladmin flush-hosts' 解决方法(转)

转自:http://www.cnblogs.com/susuyu/archive/2013/05/28/3104249.html 环境:linux,mysql5.5.21 错误:Host is blocked because of many connection errors; unblock with 'mysqladmin flush-hosts' 原因: 同一个ip在短时间内产生太多(超过mysql数据库max_connection_errors的最大值)中断的数据库连接而导致的阻塞: 解

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

环境:linux,mysql5.5.21 错误:Host is blocked because of many connection errors; unblock with 'mysqladmin flush-hosts' 原因: 同一个ip在短时间内产生太多(超过mysql数据库max_connection_errors的最大值)中断的数据库连接而导致的阻塞: 解决方法: 1.提高允许的max_connection_errors数量(治标不治本): ① 进入Mysql数据库查看max_con