fix timestamp bug

This commit is contained in:
Looly
2020-03-18 16:37:33 +08:00
parent 8fda7fe8bd
commit 4663e0d175
5 changed files with 70 additions and 11 deletions

View File

@@ -265,15 +265,14 @@ public class HandleHelper {
* @throws SQLException SQL异常
*/
private static <T> Object getColumnValue(ResultSet rs, int columnIndex, int type, Type targetColumnType) throws SQLException {
Object rawValue;
Object rawValue = null;
switch (type) {
case Types.TIMESTAMP:
try{
rawValue = rs.getTimestamp(columnIndex);
} catch (SQLException ignore){
// issue#776@Github
// 当数据库中日期为0000-00-00 00:00:00报错按照普通日期获取
rawValue = rs.getDate(columnIndex);
// 当数据库中日期为0000-00-00 00:00:00报错转为null
}
break;
case Types.TIME:

View File

@@ -5,6 +5,7 @@ import org.junit.Ignore;
import org.junit.Test;
import java.sql.SQLException;
import java.util.List;
/**
* MySQL操作单元测试
@@ -26,11 +27,11 @@ public class MySQLTest {
);
}
}
/**
* 事务测试<br>
* 更新三条信息低2条后抛出异常正常情况下三条都应该不变
*
*
* @throws SQLException SQL异常
*/
@Test(expected=SQLException.class)
@@ -56,4 +57,11 @@ public class MySQLTest {
}
}
@Test
@Ignore
public void getTimeStampTest() throws SQLException {
final List<Entity> all = Db.use("mysql").findAll("test");
Console.log(all);
}
}

View File

@@ -37,7 +37,7 @@ user = looly
pass = 123456
[mysql]
url = jdbc:mysql://looly.centos:3306/test_hutool?useSSL=false
url = jdbc:mysql://looly.centos8:3306/hutool_test?useSSL=false
user = root
pass = 123456