Example usage for java.sql CallableStatement getObject

List of usage examples for java.sql CallableStatement getObject

Introduction

In this page you can find the example usage for java.sql CallableStatement getObject.

Prototype

public <T> T getObject(String parameterName, Class<T> type) throws SQLException;

Source Link

Document

Returns an object representing the value of OUT parameter parameterName and will convert from the SQL type of the parameter to the requested Java data type, if the conversion is supported.

Usage

From source file:Test.java

public static void main(String[] args) throws Exception {
    Connection conn = DriverManager.getConnection("...", "username", "password");
    String query = "{CALL GETDATE(?,?)}";
    CallableStatement callableStatement = (CallableStatement) conn.prepareCall(query);

    callableStatement.setInt(1, 123);//w w  w . j  a  va 2 s .c  o  m
    callableStatement.registerOutParameter(1, Types.DATE);
    callableStatement.executeQuery();

    Date date = callableStatement.getObject(2, Date.class);

}