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]>
{"report":{"fcp":1007.5,"ttfb":202.30000001192093,"pageVisibility":"visible","entityId":24805,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":0.5,"journeyId":"f4b842e0-9709-4842-a2f8-b67a3f2d9635","navigationType":0,"readyForUser":1090.699999988079,"redirectCount":0,"resourceLoadedEnd":1244.800000011921,"resourceLoadedStart":207.9000000357628,"resourceTiming":[{"duration":329.39999997615814,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2bu7/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":207.9000000357628,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":207.9000000357628,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":537.3000000119209,"responseStart":0,"secureConnectionStart":0},{"duration":329.39999997615814,"initiatorType":"link","name":"https://jira.mariadb.org/s/7ebd35e77e471bc30ff0eba799ebc151-CDN/lu2bu7/820016/12ta74/8679b4946efa1a0bb029a3a22206fb5d/_/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":208.30000001192093,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":208.30000001192093,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":537.6999999880791,"responseStart":0,"secureConnectionStart":0},{"duration":355.69999998807907,"initiatorType":"script","name":"https://jira.mariadb.org/s/fbf975c0cce4b1abf04784eeae9ba1f4-CDN/lu2bu7/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":208.4000000357628,"connectEnd":208.4000000357628,"connectStart":208.4000000357628,"domainLookupEnd":208.4000000357628,"domainLookupStart":208.4000000357628,"fetchStart":208.4000000357628,"redirectEnd":0,"redirectStart":0,"requestStart":208.4000000357628,"responseEnd":564.1000000238419,"responseStart":564,"secureConnectionStart":208.4000000357628},{"duration":430.19999998807907,"initiatorType":"script","name":"https://jira.mariadb.org/s/099b33461394b8015fc36c0a4b96e19f-CDN/lu2bu7/820016/12ta74/8679b4946efa1a0bb029a3a22206fb5d/_/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":208.60000002384186,"connectEnd":208.60000002384186,"connectStart":208.60000002384186,"domainLookupEnd":208.60000002384186,"domainLookupStart":208.60000002384186,"fetchStart":208.60000002384186,"redirectEnd":0,"redirectStart":0,"requestStart":208.60000002384186,"responseEnd":638.8000000119209,"responseStart":638.8000000119209,"secureConnectionStart":208.60000002384186},{"duration":433.7999999523163,"initiatorType":"script","name":"https://jira.mariadb.org/s/94c15bff32baef80f4096a08aceae8bc-CDN/lu2bu7/820016/12ta74/c92c0caa9a024ae85b0ebdbed7fb4bd7/_/download/contextbatch/js/atl.global,-_super/batch.js?locale=en","startTime":208.9000000357628,"connectEnd":208.9000000357628,"connectStart":208.9000000357628,"domainLookupEnd":208.9000000357628,"domainLookupStart":208.9000000357628,"fetchStart":208.9000000357628,"redirectEnd":0,"redirectStart":0,"requestStart":208.9000000357628,"responseEnd":642.6999999880791,"responseStart":642.6999999880791,"secureConnectionStart":208.9000000357628},{"duration":434.10000002384186,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bu7/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-en/jira.webresources:calendar-en.js","startTime":209,"connectEnd":209,"connectStart":209,"domainLookupEnd":209,"domainLookupStart":209,"fetchStart":209,"redirectEnd":0,"redirectStart":0,"requestStart":209,"responseEnd":643.1000000238419,"responseStart":643.1000000238419,"secureConnectionStart":209},{"duration":434.30000001192093,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bu7/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-localisation-moment/jira.webresources:calendar-localisation-moment.js","startTime":209.19999998807907,"connectEnd":209.19999998807907,"connectStart":209.19999998807907,"domainLookupEnd":209.19999998807907,"domainLookupStart":209.19999998807907,"fetchStart":209.19999998807907,"redirectEnd":0,"redirectStart":0,"requestStart":209.19999998807907,"responseEnd":643.5,"responseStart":643.5,"secureConnectionStart":209.19999998807907},{"duration":496.80000001192093,"initiatorType":"link","name":"https://jira.mariadb.org/s/b04b06a02d1959df322d9cded3aeecc1-CDN/lu2bu7/820016/12ta74/a2ff6aa845ffc9a1d22fe23d9ee791fc/_/download/contextbatch/css/jira.global.look-and-feel,-_super/batch.css","startTime":209.30000001192093,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":209.30000001192093,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":706.1000000238419,"responseStart":0,"secureConnectionStart":0},{"duration":434.5,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":209.5,"connectEnd":209.5,"connectStart":209.5,"domainLookupEnd":209.5,"domainLookupStart":209.5,"fetchStart":209.5,"redirectEnd":0,"redirectStart":0,"requestStart":209.5,"responseEnd":644,"responseStart":644,"secureConnectionStart":209.5},{"duration":496.5,"initiatorType":"link","name":"https://jira.mariadb.org/s/3ac36323ba5e4eb0af2aa7ac7211b4bb-CDN/lu2bu7/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":209.69999998807907,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":209.69999998807907,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":706.1999999880791,"responseStart":0,"secureConnectionStart":0},{"duration":434.69999998807907,"initiatorType":"script","name":"https://jira.mariadb.org/s/3339d87fa2538a859872f2df449bf8d0-CDN/lu2bu7/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":209.80000001192093,"connectEnd":209.80000001192093,"connectStart":209.80000001192093,"domainLookupEnd":209.80000001192093,"domainLookupStart":209.80000001192093,"fetchStart":209.80000001192093,"redirectEnd":0,"redirectStart":0,"requestStart":209.80000001192093,"responseEnd":644.5,"responseStart":644.5,"secureConnectionStart":209.80000001192093},{"duration":1033.800000011921,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bu7/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-js/jira.webresources:bigpipe-js.js","startTime":210.60000002384186,"connectEnd":210.60000002384186,"connectStart":210.60000002384186,"domainLookupEnd":210.60000002384186,"domainLookupStart":210.60000002384186,"fetchStart":210.60000002384186,"redirectEnd":0,"redirectStart":0,"requestStart":210.60000002384186,"responseEnd":1244.4000000357628,"responseStart":1244.4000000357628,"secureConnectionStart":210.60000002384186},{"duration":1034.1000000238419,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bu7/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-init/jira.webresources:bigpipe-init.js","startTime":210.69999998807907,"connectEnd":210.69999998807907,"connectStart":210.69999998807907,"domainLookupEnd":210.69999998807907,"domainLookupStart":210.69999998807907,"fetchStart":210.69999998807907,"redirectEnd":0,"redirectStart":0,"requestStart":210.69999998807907,"responseEnd":1244.800000011921,"responseStart":1244.800000011921,"secureConnectionStart":210.69999998807907},{"duration":434.7999999523163,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":717.9000000357628,"connectEnd":717.9000000357628,"connectStart":717.9000000357628,"domainLookupEnd":717.9000000357628,"domainLookupStart":717.9000000357628,"fetchStart":717.9000000357628,"redirectEnd":0,"redirectStart":0,"requestStart":717.9000000357628,"responseEnd":1152.699999988079,"responseStart":1152.699999988079,"secureConnectionStart":717.9000000357628},{"duration":257.89999997615814,"initiatorType":"script","name":"https://www.google-analytics.com/analytics.js","startTime":1001.9000000357628,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":1001.9000000357628,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1259.800000011921,"responseStart":0,"secureConnectionStart":0}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":33,"responseStart":203,"responseEnd":204,"domLoading":206,"domInteractive":1265,"domContentLoadedEventStart":1265,"domContentLoadedEventEnd":1306,"domComplete":2856,"loadEventStart":2856,"loadEventEnd":2857,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1249.199999988079},{"name":"bigPipe.sidebar-id.end","time":1250},{"name":"bigPipe.activity-panel-pipe-id.start","time":1250.1000000238419},{"name":"bigPipe.activity-panel-pipe-id.end","time":1252.4000000357628},{"name":"activityTabFullyLoaded","time":1311.800000011921}],"measures":[],"correlationId":"5ea27e4809efc6","effectiveType":"4g","downlink":9.6,"rtt":0,"serverDuration":93,"dbReadsTimeInMs":8,"dbConnsTimeInMs":16,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}