TIMESTAMP Query
843859May 14 2008 — edited Nov 20 2014I am trying to run a sql query "SELECT SYSDATE FROM DUAL" in order to get the output I tried rs.getObject(1) and I got the sysdate , that's ok . But while trying to do the same thing with query "SELECT CAST(SYSDATE AS TIMESTAMP)FROM DUAL" I got the output as "oracle.sql.TIMESTAMP@1ddebc3" . Again if I use rs.getString(1) instead of rs.getObject(1) for the second query I got the proper result.
Any Idea why this happens ? Below is my program that I tried to run.
import java.sql.*;
class JdbcConnectTest {
public static void main (String args []) throws SQLException
{
try{
Connection con=null;
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn = DriverManager.getConnection
("jdbc:oracle:thin:@localhost:1521:ORCL", "scott", "tiger");
// @machineName:port:SID, userid, password
Statement stmt = conn.createStatement();
ResultSet rset = stmt.executeQuery("SELECT CAST(SYSDATE AS TIMESTAMP)FROM DUAL");
while (rset.next())
System.out.println (rset.getObject(1)); // Print col 1
stmt.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
}