Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

It returns a java.sql.Timestamp, not java.sql.Date instance.

select current_timestamp from dule

It returns a oracle.sql.TIMESTAMPTZ, not java.sql.Timestamp instance.

How to make them return values of JDBC java.sql.* standard types?

In Oracle, a DATE data type has year, month, day, hour, minute and second components.

In Java:

  • a java.sql.Date class has year, month and day components.
  • a java.sql.Timestamp class has year, month, day, hour, minute and second components.
  • The correct Java data type for an Oracle DATE is java.sql.Timestamp and not java.sql.Date (you can use java.sql.Date as the return value from stored procedures, etc. but it will truncate the time components).

    In Oracle, CURRENT_TIMESTAMP has the data type TIMESTAMP WITH TIME ZONE. In Java, this is the equivalent of oracle.sql.TIMESTAMPTZ class.

    Oracle SQL returns Oracle data types. You can use trunc(current_date) to get rid of the time part (not that it will affect the return type, though!). However, to get the right data type with JDBC, simply use the proper get method in https://docs.oracle.com/javase/8/docs/api/java/sql/ResultSet.html. The getDate method returns a java.sql.Date, the getTimestamp method returns a java.sql.Timestamp.

    getXXX() vs getObject(): When using getXXX(...) methods, resultSet.getInt(index) throws exception if it is null. How to deal with null values? – eastwater May 14, 2018 at 20:48 You need to check if the result set has any data. example., while (resultSet.next()) { System.out.println(resultSet.getString(1) + " " + resultSet.getString(2)); } – Nirmala May 14, 2018 at 22:47 Actually getInt is documented to return 0 for null values. You can use wasNull to check if it was null or not. If you get a NullPointerException for getInt, post the stack trace. – ewramner May 15, 2018 at 6:32

    Thanks for contributing an answer to Stack Overflow!

    • Please be sure to answer the question. Provide details and share your research!

    But avoid

    • Asking for help, clarification, or responding to other answers.
    • Making statements based on opinion; back them up with references or personal experience.

    To learn more, see our tips on writing great answers.