Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MySQL: java setObject() to set time does not work #5

Closed
stephanievu opened this issue May 2, 2019 · 2 comments
Closed

MySQL: java setObject() to set time does not work #5

stephanievu opened this issue May 2, 2019 · 2 comments
Assignees

Comments

@stephanievu
Copy link
Contributor

stephanievu commented May 2, 2019

This works fine with Oracle DB but does not work with MySQL DB. After setting time with setObject(), I get back time of 00:00:00

What I Did
Java codes:
Statement st = dbConn.createStatement();
PreparedStatement pst = dbConn.prepareStatement(
"insert into jdbc_occ_test (id, int_val, str_val, char_val, float_val, raw_val, blob_val, clob_val, date_val, "

  • "time_val, timestamp_val, timestamp_tz_val) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
    ......
    pst.setObject(10, new Time(now).toString(), Types.TIME);
    pst.executeUpdate();
    ....

ResultSet rs = st.executeQuery( "select id, int_val, str_val, char_val, float_val, raw_val, blob_val, " +
"clob_val, date_val, time_val, timestamp_val from jdbc_occ_test where id=" + iID_START);
rs.next();
System.out.println ("Time is " + rs.getTime(10).toString());

What I Expected
Results:
Inserted time: 10:49:32
Time getting back: 10:49:32

What I Saw Instead
Results:
Inserted time: 10:49:32
Time getting back: 00:00:00

@ModEtchFill ModEtchFill self-assigned this May 17, 2019
sssinghsyr added a commit that referenced this issue Jun 28, 2019
@ModEtchFill ModEtchFill reopened this Jul 24, 2019
@ModEtchFill
Copy link
Collaborator

Issue used setObject() while the revised test used setString()

@ModEtchFill
Copy link
Collaborator

Team concluded not-a-bug.

The DATE type is used for values with a date part but no time part. MySQL retrieves and displays DATE values in 'YYYY-MM-DD' format.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants