Class OutParameter<T>

  • Type Parameters:
    T - the class of the parameter; should be compatible via cast with the class returned by the CallableStatement.getObject(int) method.

    public class OutParameter<T>
    extends java.lang.Object
    Represents an OUT parameter for a stored procedure. When running a stored procedure with QueryRunner, pass an instance of OutParameter to indicate that the parameter at that index is an OUT parameter. The value of the parameter may be obtained from the OutParameter instance via getValue().

    INOUT parameters are also supported by setting the value of the OutParameter instance before invoking the stored procedure.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.lang.Class<T> javaType  
      private int sqlType  
      private T value  
    • Constructor Summary

      Constructors 
      Constructor Description
      OutParameter​(int sqlType, java.lang.Class<T> javaType)
      Construct an OutParameter for the given JDBC SQL type and Java type.
      OutParameter​(int sqlType, java.lang.Class<T> javaType, T value)
      Construct an OutParameter for the given JDBC SQL type and Java type and with the given value.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.Class<T> getJavaType()
      Get the Java class for this OUT parameter.
      int getSqlType()
      Get the JDBC SQL type for this OUT parameter.
      T getValue()
      Get the value of the OUT parameter.
      (package private) void register​(java.sql.CallableStatement stmt, int index)
      Set up the given statement by registering an OUT parameter at the given index using the sqlType and value of this OutParameter.
      (package private) void setValue​(java.sql.CallableStatement stmt, int index)
      Set the value using the return value of the parameter an the given index from the given CallableStatement.
      void setValue​(T value)
      Set the value of the OUT parameter.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • sqlType

        private final int sqlType
      • javaType

        private final java.lang.Class<T> javaType
      • value

        private T value
    • Constructor Detail

      • OutParameter

        public OutParameter​(int sqlType,
                            java.lang.Class<T> javaType)
        Construct an OutParameter for the given JDBC SQL type and Java type.
        Parameters:
        sqlType - the JDBC SQL type of the parameter as in java.sql.Types.
        javaType - the Java class of the parameter value, cast compatible with the type returned by CallableStatement.getObject(int) for the JDBC type given by sqlType.
      • OutParameter

        public OutParameter​(int sqlType,
                            java.lang.Class<T> javaType,
                            T value)
        Construct an OutParameter for the given JDBC SQL type and Java type and with the given value. The parameter will be treated as an INOUT parameter if the value is null.
        Parameters:
        sqlType - the JDBC SQL type of the parameter as in java.sql.Types.
        javaType - the Java class of the parameter value, cast compatible with the type returned by CallableStatement.getObject(int) for the JDBC type given by sqlType.
        value - the IN value of the parameter
    • Method Detail

      • getSqlType

        public int getSqlType()
        Get the JDBC SQL type for this OUT parameter.
        Returns:
        the JDBC SQL type for this OUT parameter.
      • getJavaType

        public java.lang.Class<T> getJavaType()
        Get the Java class for this OUT parameter.
        Returns:
        the Java class for this OUT parameter.
      • getValue

        public T getValue()
        Get the value of the OUT parameter. After the stored procedure has been executed, the value is the value returned via this parameter.
        Returns:
        the value of the OUT parameter.
      • setValue

        public void setValue​(T value)
        Set the value of the OUT parameter. If the value is not null when the stored procedure is executed, then the parameter will be treated like an INOUT parameter.
        Parameters:
        value - the new value for the parameter.
      • setValue

        void setValue​(java.sql.CallableStatement stmt,
                      int index)
               throws java.sql.SQLException
        Set the value using the return value of the parameter an the given index from the given CallableStatement.
        Parameters:
        stmt - the already executed statement
        index - the (1-based) index of the parameter
        Throws:
        java.sql.SQLException - when the value could not be retrieved from the statement.
      • register

        void register​(java.sql.CallableStatement stmt,
                      int index)
               throws java.sql.SQLException
        Set up the given statement by registering an OUT parameter at the given index using the sqlType and value of this OutParameter. If the value is not null, the parameter is treated like an INOUT parameter and the value is set on the statement.
        Parameters:
        stmt - the statement the parameter should register on.
        index - the (1-based) index of the parameter.
        Throws:
        java.sql.SQLException - if the parameter could not be registered, or if the value of the parameter could not be set.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object