简体   繁体   中英

Java JDBC SQL Syntax error with PreparedStatement.setTimestamp. Value gets cut off at the colon ':' in time

Whenever I try to execute a prepared statement, it throws a MySQLSyntaxErrorException with:

You have an error in your SQL syntax; check the manual that corresponds to your
MySQL server version for the right syntax to use near 'INSERT INTO Information (stamp) VALUES ('2017-01-24 1' at **line 1

It looks like it's getting cut off at the colon ":' of the time part of the format.

String sql = "INSERT INTO Information (stamp) VALUES (?);"
...
statement.setTimeStamp(1, new Timestamp(system.currentTimeMillis()));

I've tried a bunch of different ways of getting a system time stamp and converting it to java.sql.Timestamp, but it continues to throw that same error.

My table has a column stamp of type TIMESTAMP.

Ah I found the problem. I didn't realize that prepared statements did not allow multiple queries. My options were to use two statements or add on a connection parameter while sending my connection request

?allowMultipleQueries=true . This allows multiple queries separated by a semi-colon. Thanks yall!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM