D
D
Dmitry2017-01-27 19:48:29
Java
Dmitry, 2017-01-27 19:48:29

Is using java.sql.Timestamp outside the DAO layer an anti-pattern?

Those. if the application code outside the DAO layer does not require specific Timestamp methods, such as getNanos(), then there is no need to use a jdbc-specific class in the rest of the application code. By using java.sql.Timestamp we are only increasing the coupling between classes, and should strive for the opposite.
I would like to hear opinions on this.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nikolai, 2017-02-07
@j_wayne

A thin wrapper around java.util.Date that allows the JDBC API to identify this as an SQL TIMESTAMP value. It adds the ability to hold the SQL TIMESTAMP fractional seconds value, by allowing the specification of fractional seconds to a precision of nanoseconds. A Timestamp also provides formatting and parsing operations to support the JDBC escape syntax for timestamp values.

I don't quite understand the issue.
Indeed, if there is no need for all this, then yes, java.util.Date is enough (by the way, classes for working with time were added in Java 7-8).
If there is a need, then I do not see any problem. It is in the standard class library. No extra dependency is added.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question