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

Saving Dates #305

Open
fredericoregateiro opened this issue Oct 23, 2018 · 1 comment
Open

Saving Dates #305

fredericoregateiro opened this issue Oct 23, 2018 · 1 comment

Comments

@fredericoregateiro
Copy link

It is possible to save da Date property like a date on a database instead of a timestamp?
In my class i have:

    private Date systemEntryDate;

    public Date getSystemEntryDate() {
        return systemEntryDate;
    }

    public void setSystemEntryDate(Date systemEntryDate) {
        this.systemEntryDate = systemEntryDate;
    }

and the database i have to use is a existing sqlite3 db, containing the values on the SystemEntryDate column like 2018-10-23 10:16:27.8871829

and the values stored in this column by sql2o is a timestamp like 1540306987843.

Can i change this behavior, and store a date?

@fredericoregateiro
Copy link
Author

The only way i was able to accomplish this was to create a formater and use the format as a parameter:

SimpleDateFormat dateTimeformatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

PreparedStatement stmt = connection.prepareStatement(query);
stmt.setObject(1, dateTimeformatter.format(date), java.sql.Types.DATE);

and with sqlo like this:

transaction.createQuery(query)
.addParameter("SystemEntryDate", dateTimeformatter.format(document.getSystemEntryDate()))
.executeUpdate()

Is there a better way?

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

1 participant