In my application i have a java Timestamp dateCreated, which is inserted to a mysql Timestamp colum. Inserting is no problem, i use a prepared statement and statement.setTimestamp(dateCreated).

Now i need to select a row with the dateCreated as unique identifier. my method gets another java Timestamp object.how does the SQL query work in this case? i havent figured out how to compare the java timestamp to the mysql one.

SELECT * FROM table WHERE timestamp_column = ???

Thanks!

有帮助吗?

解决方案

In Java you will use a similar setTimestamp method as you did with the insert.

   Timestamp t = ???;


   String sql = "SELECT * FROM table WHERE timestamp_column = ?";
   preparedStatement = conn.prepareStatement(sql);
   preparedStatement.setTimestamp(t);

etc.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top