Type:
Bug
Priority:
Minor
Resolution:
Fixed
Affects Version/s:
1.1.3
Fix Version/s:
None
Component/s:
None
When calling setObject(new Date(), Types.TimeStamp) from a Preparedstatement the field is filled with a zero date String.
When you wrap the Date in a Timestamp Object it's working as expected.
Steps to reproduce:
Execute the follwing testcase:
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.sql.*;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;
import static org.junit.Assert.assertEquals;
public class MariaDBDateTest {
private static final String url =
"jdbc:mysql://" +
// "jdbc:mariadb://" +
System.getProperty("hostname", "localhost") + ":" +
System.getProperty("port", "3306") + "/" +
System.getProperty("dbname", "test");
private static final String user = "root";
private static final String passwd = "";
private Connection con;
private Date date;
@Before
public void setUp() throws Exception {
// Load in the DriverManager Class
Class.forName("org.mariadb.jdbc.Driver");
// Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection(url, user, passwd);
date = Calendar.getInstance(TimeZone.getTimeZone()).getTime();
// new Date();
// Calendar.getInstance().getTime();
createDB();
System.out.println("Setup Complete.");
System.out.println("**********");
}
@After
public void tearDown() throws Exception {
con.close();
System.out.println("Teardown Complete.");
System.out.println("**********");
}
private void createDB() throws Exception {
con.setAutoCommit(true);
PreparedStatement pstmt_drop = con.prepareStatement("DROP TABLE IF EXISTS test_table");
try {
pstmt_drop.executeUpdate();
} catch (Throwable t) {
}
PreparedStatement pstmt_create = con.prepareStatement("CREATE TABLE test_table " +
"(" +
"id INT PRIMARY KEY, " +
"someDate1 DATETIME(3)," +
"someDate2 DATETIME(3)" +
")");
pstmt_create.executeUpdate();
}
@Test
public void testDateTime() throws Exception {
PreparedStatement pstmt_add = con.prepareStatement("INSERT INTO test_table (id, someDate1, someDate2) VALUES (?, ?, ?)");
pstmt_add.setInt(1, 1);
pstmt_add.setObject(2, new Timestamp(date.getTime()), Types.TIMESTAMP);
pstmt_add.setObject(3, date, Types.TIMESTAMP);
pstmt_add.executeUpdate();
String sql = "SELECT ID, someDate1, someDate2 FROM test_table t0 WHERE ID = ?";
PreparedStatement pstmt = con.prepareStatement(sql);
pstmt.setInt(1, 1);
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
assertEquals(1, rs.getInt(1));
assertEquals(date, rs.getObject(2));
// assertEquals(date, rs.getObject(3));
}
}
}
Then execute mariadb client
MariaDB [test]> select * from test_table;
+----+-------------------------+-------------------------+
| id | someDate1 | someDate2 |
+----+-------------------------+-------------------------+
| 1 | 2013-07-19 07:00:17.452 | 0000-00-00 00:00:00.000 |
+----+-------------------------+-------------------------+
1 row in set (0.00 sec)
MariaDB [test]>
Frank S
created issue -
2013-07-19 08:03
Vladislav Vaintroub
made changes -
2013-07-19 11:11
Field
Original Value
New Value
Priority
Major
[ 3
]
Minor
[ 4
]
Vladislav Vaintroub
made changes -
2013-07-24 11:57
Resolution
Fixed
[ 1
]
Status
Open
[ 1
]
Closed
[ 6
]
Vladislav Vaintroub
made changes -
2013-07-24 11:58
Assignee
Rasmus Johansson
[ ratzpo
]
Vladislav Vaintroub
[ wlad
]
Resolution
Fixed
[ 1
]
Status
Closed
[ 6
]
Reopened
[ 4
]
Vladislav Vaintroub
made changes -
2013-07-24 11:58
Resolution
Fixed
[ 1
]
Status
Reopened
[ 4
]
Closed
[ 6
]
Sergei Golubchik
made changes -
2021-12-06 21:27
Workflow
MariaDB v3
[ 70216
]
MariaDB v4
[ 134690
]
{"report":{"fcp":1330.4000000953674,"ttfb":412.7000002861023,"pageVisibility":"visible","entityId":24805,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":0.5,"journeyId":"6ed2b6a7-c03a-42a7-b025-8778d944e908","navigationType":0,"readyForUser":1422.4000000953674,"redirectCount":0,"resourceLoadedEnd":996.7000002861023,"resourceLoadedStart":418.5,"resourceTiming":[{"duration":191,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":418.5,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":418.5,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":609.5,"responseStart":0,"secureConnectionStart":0},{"duration":192.09999990463257,"initiatorType":"link","name":"https://jira.mariadb.org/s/7ebd35e77e471bc30ff0eba799ebc151-CDN/lu2cib/820016/12ta74/2bf333562ca6724060a9d5f1535471f6/_/download/contextbatch/css/jira.browse.project,project.issue.navigator,jira.view.issue,jira.general,jira.global,atl.general,-_super/batch.css?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&slack-enabled=true","startTime":418.80000019073486,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":418.80000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":610.9000000953674,"responseStart":0,"secureConnectionStart":0},{"duration":432.30000019073486,"initiatorType":"script","name":"https://jira.mariadb.org/s/0917945aaa57108d00c5076fea35e069-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":419,"connectEnd":419,"connectStart":419,"domainLookupEnd":419,"domainLookupStart":419,"fetchStart":419,"redirectEnd":0,"redirectStart":0,"requestStart":619.4000000953674,"responseEnd":851.3000001907349,"responseStart":700.7000002861023,"secureConnectionStart":419},{"duration":577.5,"initiatorType":"script","name":"https://jira.mariadb.org/s/2d8175ec2fa4c816e8023260bd8c1786-CDN/lu2cib/820016/12ta74/2bf333562ca6724060a9d5f1535471f6/_/download/contextbatch/js/jira.browse.project,project.issue.navigator,jira.view.issue,jira.general,jira.global,atl.general,-_super/batch.js?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&locale=en&slack-enabled=true","startTime":419.2000002861023,"connectEnd":419.2000002861023,"connectStart":419.2000002861023,"domainLookupEnd":419.2000002861023,"domainLookupStart":419.2000002861023,"fetchStart":419.2000002861023,"redirectEnd":0,"redirectStart":0,"requestStart":619.5999999046326,"responseEnd":996.7000002861023,"responseStart":677.2000002861023,"secureConnectionStart":419.2000002861023},{"duration":221.80000019073486,"initiatorType":"script","name":"https://jira.mariadb.org/s/a9324d6758d385eb45c462685ad88f1d-CDN/lu2cib/820016/12ta74/c92c0caa9a024ae85b0ebdbed7fb4bd7/_/download/contextbatch/js/atl.global,-_super/batch.js?locale=en","startTime":419.40000009536743,"connectEnd":419.40000009536743,"connectStart":419.40000009536743,"domainLookupEnd":419.40000009536743,"domainLookupStart":419.40000009536743,"fetchStart":419.40000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":619.8000001907349,"responseEnd":641.2000002861023,"responseStart":639.5,"secureConnectionStart":419.40000009536743},{"duration":255.09999990463257,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-en/jira.webresources:calendar-en.js","startTime":419.5,"connectEnd":419.5,"connectStart":419.5,"domainLookupEnd":419.5,"domainLookupStart":419.5,"fetchStart":419.5,"redirectEnd":0,"redirectStart":0,"requestStart":621.5,"responseEnd":674.5999999046326,"responseStart":672.2000002861023,"secureConnectionStart":419.5},{"duration":254.2999997138977,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-localisation-moment/jira.webresources:calendar-localisation-moment.js","startTime":419.7000002861023,"connectEnd":419.7000002861023,"connectStart":419.7000002861023,"domainLookupEnd":419.7000002861023,"domainLookupStart":419.7000002861023,"fetchStart":419.7000002861023,"redirectEnd":0,"redirectStart":0,"requestStart":621.7000002861023,"responseEnd":674,"responseStart":642.5,"secureConnectionStart":419.7000002861023},{"duration":200.7000002861023,"initiatorType":"link","name":"https://jira.mariadb.org/s/b04b06a02d1959df322d9cded3aeecc1-CDN/lu2cib/820016/12ta74/a2ff6aa845ffc9a1d22fe23d9ee791fc/_/download/contextbatch/css/jira.global.look-and-feel,-_super/batch.css","startTime":420,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":420,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":620.7000002861023,"responseStart":0,"secureConnectionStart":0},{"duration":256.5,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":420.2000002861023,"connectEnd":420.2000002861023,"connectStart":420.2000002861023,"domainLookupEnd":420.2000002861023,"domainLookupStart":420.2000002861023,"fetchStart":420.2000002861023,"redirectEnd":0,"redirectStart":0,"requestStart":623.5,"responseEnd":676.7000002861023,"responseStart":675.7000002861023,"secureConnectionStart":420.2000002861023},{"duration":202.19999980926514,"initiatorType":"link","name":"https://jira.mariadb.org/s/3ac36323ba5e4eb0af2aa7ac7211b4bb-CDN/lu2cib/820016/12ta74/d176f0986478cc64f24226b3d20c140d/_/download/contextbatch/css/com.atlassian.jira.projects.sidebar.init,-_super,-project.issue.navigator,-jira.view.issue/batch.css?jira.create.linked.issue=true","startTime":420.40000009536743,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":420.40000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":622.5999999046326,"responseStart":0,"secureConnectionStart":0},{"duration":289.90000009536743,"initiatorType":"script","name":"https://jira.mariadb.org/s/5d5e8fe91fbc506585e83ea3b62ccc4b-CDN/lu2cib/820016/12ta74/d176f0986478cc64f24226b3d20c140d/_/download/contextbatch/js/com.atlassian.jira.projects.sidebar.init,-_super,-project.issue.navigator,-jira.view.issue/batch.js?jira.create.linked.issue=true&locale=en","startTime":420.5,"connectEnd":420.5,"connectStart":420.5,"domainLookupEnd":420.5,"domainLookupStart":420.5,"fetchStart":420.5,"redirectEnd":0,"redirectStart":0,"requestStart":628.3000001907349,"responseEnd":710.4000000953674,"responseStart":708.5,"secureConnectionStart":420.5},{"duration":541.6999998092651,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-js/jira.webresources:bigpipe-js.js","startTime":426.7000002861023,"connectEnd":426.7000002861023,"connectStart":426.7000002861023,"domainLookupEnd":426.7000002861023,"domainLookupStart":426.7000002861023,"fetchStart":426.7000002861023,"redirectEnd":0,"redirectStart":0,"requestStart":940.8000001907349,"responseEnd":968.4000000953674,"responseStart":964.0999999046326,"secureConnectionStart":426.7000002861023},{"duration":541.9000000953674,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-init/jira.webresources:bigpipe-init.js","startTime":426.80000019073486,"connectEnd":426.80000019073486,"connectStart":426.80000019073486,"domainLookupEnd":426.80000019073486,"domainLookupStart":426.80000019073486,"fetchStart":426.80000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":941.8000001907349,"responseEnd":968.7000002861023,"responseStart":964.9000000953674,"secureConnectionStart":426.80000019073486},{"duration":224.7999997138977,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":993.7000002861023,"connectEnd":993.7000002861023,"connectStart":993.7000002861023,"domainLookupEnd":993.7000002861023,"domainLookupStart":993.7000002861023,"fetchStart":993.7000002861023,"redirectEnd":0,"redirectStart":0,"requestStart":1178.5,"responseEnd":1218.5,"responseStart":1214.9000000953674,"secureConnectionStart":993.7000002861023}],"fetchStart":1,"domainLookupStart":140,"domainLookupEnd":148,"connectStart":148,"connectEnd":175,"secureConnectionStart":163,"requestStart":176,"responseStart":413,"responseEnd":418,"domLoading":417,"domInteractive":1512,"domContentLoadedEventStart":1512,"domContentLoadedEventEnd":1579,"domComplete":2662,"loadEventStart":2663,"loadEventEnd":2663,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1478},{"name":"bigPipe.sidebar-id.end","time":1478.7000002861023},{"name":"bigPipe.activity-panel-pipe-id.start","time":1478.9000000953674},{"name":"bigPipe.activity-panel-pipe-id.end","time":1482.2000002861023},{"name":"activityTabFullyLoaded","time":1597}],"measures":[],"correlationId":"9eedf7bf21cdc2","effectiveType":"4g","downlink":9.2,"rtt":0,"serverDuration":125,"dbReadsTimeInMs":21,"dbConnsTimeInMs":29,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
Is there any good reason to use java.util.Date() instead of appropriate datatype (java.util.Timestamp?)