Hebert Coelho wrote:How is your date column? It is set up to be date and time?
Paul Clapham wrote:So then setTimestamp is the method you should call. If you want the milliseconds set to zero, then do that before you call setTimestamp.
Paul Clapham wrote:When you say "queries" I assume you're talking about Java code which gets data from the database. In which case it's completely up to you how you display the dates. You can display them with or without milliseconds. That has nothing to do with how you store the data in the database.
Paul Clapham wrote:So far I pointed out that (a) you can set the milliseconds to zero before you insert the timestamp into the database, and (b) you can display the timestamp without milliseconds after you extract it from the database.
As far as I can see that takes care of all your objections. You're going to have to explain what your problem is if it isn't one of those two.
Gabriel Beres wrote:Paul, we are not on the same page.
(b) Do you understand, that i'm using prepared statement to make the query? If yes, it should be obvious, that i can only bind my query parameters with setDate() or setTimestamp(). The actual problem is, that if i bind with setDate(), then it will be yyyyMMdd. If i use setTimestamp it will be yyyyMMdd HHMMsss +miliseconds.
In that case i think i have no possibility to format it myself.
Paul Clapham wrote:
Gabriel Beres wrote:Paul, we are not on the same page.
(b) Do you understand, that i'm using prepared statement to make the query? If yes, it should be obvious, that i can only bind my query parameters with setDate() or setTimestamp(). The actual problem is, that if i bind with setDate(), then it will be yyyyMMdd. If i use setTimestamp it will be yyyyMMdd HHMMsss +miliseconds.
In that case i think i have no possibility to format it myself.
I have said twice that you could set the milliseconds of a timestamp to zero before inserting that timestamp into the database. What you're saying doesn't make any sense. The database doesn't store anything in any format at all. It's only when you extract something from the database and display it that formatting takes place. So you're right, I don't know what page you're on. You're going to have to explain more carefully why you think formatting has anything to do with storing the data in the database.
Gabriel Beres wrote:I'm a visual type. Could you please show me how to format the parameter to yyyyMMdd HHmm (without milliseconds) by constructing the query using setTimestamp() method of prepared statement?
Paul Clapham wrote:
Gabriel Beres wrote:I'm a visual type. Could you please show me how to format the parameter to yyyyMMdd HHmm (without milliseconds) by constructing the query using setTimestamp() method of prepared statement?
I'm sorry, I find that question too confusing to answer. Let me say a few things about it and maybe we can figure out some other question.
First, I don't understand what it means to "format a parameter". A parameter of what?
And second, if I were to format a parameter, whatever that means, I wouldn't do it by constructing a database query.
So as I said, I'm completely lost. Could you rephrase that question?
Paul Clapham wrote:Now I understand.
And I've said several times already that you should just set the milliseconds part of the timestamp to zero before you pass it to the setTimestamp() method. You would use a Calendar object to do that. Here's an outline of how to do it:
Create a Calendar object.
Set its time to your "date" value.
Set the milliseconds to zero.
Get the Calendar's time value into a java.util.Date object.
Make a java.sql.Timestamp from that.
Gabriel Beres wrote:but my understanding was, that the milliseconds would be still there, but with zero value.
Consider Paul's rocket mass heater. |