jdk/src/share/classes/java/sql/CallableStatement.java
changeset 15278 e081d3f73b75
parent 14342 8435a30053c1
child 16024 3f2bf7857375
equal deleted inserted replaced
15277:245068ba31b3 15278:e081d3f73b75
     1 /*
     1 /*
     2  * Copyright (c) 1996, 2012, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
  1077      */
  1077      */
  1078     void setBinaryStream(String parameterName, java.io.InputStream x,
  1078     void setBinaryStream(String parameterName, java.io.InputStream x,
  1079                          int length) throws SQLException;
  1079                          int length) throws SQLException;
  1080 
  1080 
  1081     /**
  1081     /**
  1082      * Sets the value of the designated parameter with the given object. The second
  1082      * Sets the value of the designated parameter with the given object.
  1083      * argument must be an object type; for integral values, the
       
  1084      * <code>java.lang</code> equivalent objects should be used.
       
  1085      *
  1083      *
  1086      * <p>The given Java object will be converted to the given targetSqlType
  1084      * <p>The given Java object will be converted to the given targetSqlType
  1087      * before being sent to the database.
  1085      * before being sent to the database.
  1088      *
  1086      *
  1089      * If the object has a custom mapping (is of a class implementing the
  1087      * If the object has a custom mapping (is of a class implementing the
  1107      *          this is the number of digits after the decimal point.  For all other
  1105      *          this is the number of digits after the decimal point.  For all other
  1108      *          types, this value will be ignored.
  1106      *          types, this value will be ignored.
  1109      * @exception SQLException if parameterName does not correspond to a named
  1107      * @exception SQLException if parameterName does not correspond to a named
  1110      * parameter; if a database access error occurs or
  1108      * parameter; if a database access error occurs or
  1111      * this method is called on a closed <code>CallableStatement</code>
  1109      * this method is called on a closed <code>CallableStatement</code>
  1112      * @exception SQLFeatureNotSupportedException if <code>targetSqlType</code> is
  1110      * @exception SQLFeatureNotSupportedException if
  1113      * a <code>ARRAY</code>, <code>BLOB</code>, <code>CLOB</code>,
  1111      * the JDBC driver does not support this data type
  1114      * <code>DATALINK</code>, <code>JAVA_OBJECT</code>, <code>NCHAR</code>,
       
  1115      * <code>NCLOB</code>, <code>NVARCHAR</code>, <code>LONGNVARCHAR</code>,
       
  1116      *  <code>REF</code>, <code>ROWID</code>, <code>SQLXML</code>
       
  1117      * or  <code>STRUCT</code> data type and the JDBC driver does not support
       
  1118      * this data type
       
  1119      * @see Types
  1112      * @see Types
  1120      * @see #getObject
  1113      * @see #getObject
  1121      * @since 1.4
  1114      * @since 1.4
  1122      */
  1115      */
  1123     void setObject(String parameterName, Object x, int targetSqlType, int scale)
  1116     void setObject(String parameterName, Object x, int targetSqlType, int scale)
  1124         throws SQLException;
  1117         throws SQLException;
  1125 
  1118 
  1126     /**
  1119     /**
  1127      * Sets the value of the designated parameter with the given object.
  1120      * Sets the value of the designated parameter with the given object.
  1128      * This method is like the method <code>setObject</code>
  1121      *
  1129      * above, except that it assumes a scale of zero.
  1122      * This method is similar to {@link #setObject(String parameterName,
       
  1123      * Object x, int targetSqlType, int scaleOrLength)},
       
  1124      * except that it assumes a scale of zero.
  1130      *
  1125      *
  1131      * @param parameterName the name of the parameter
  1126      * @param parameterName the name of the parameter
  1132      * @param x the object containing the input parameter value
  1127      * @param x the object containing the input parameter value
  1133      * @param targetSqlType the SQL type (as defined in java.sql.Types) to be
  1128      * @param targetSqlType the SQL type (as defined in java.sql.Types) to be
  1134      *                      sent to the database
  1129      *                      sent to the database
  1135      * @exception SQLException if parameterName does not correspond to a named
  1130      * @exception SQLException if parameterName does not correspond to a named
  1136      * parameter; if a database access error occurs or
  1131      * parameter; if a database access error occurs or
  1137      * this method is called on a closed <code>CallableStatement</code>
  1132      * this method is called on a closed <code>CallableStatement</code>
  1138      * @exception SQLFeatureNotSupportedException if <code>targetSqlType</code> is
  1133      * @exception SQLFeatureNotSupportedException if
  1139      * a <code>ARRAY</code>, <code>BLOB</code>, <code>CLOB</code>,
  1134      * the JDBC driver does not support this data type
  1140      * <code>DATALINK</code>, <code>JAVA_OBJECT</code>, <code>NCHAR</code>,
       
  1141      * <code>NCLOB</code>, <code>NVARCHAR</code>, <code>LONGNVARCHAR</code>,
       
  1142      *  <code>REF</code>, <code>ROWID</code>, <code>SQLXML</code>
       
  1143      * or  <code>STRUCT</code> data type and the JDBC driver does not support
       
  1144      * this data type
       
  1145      * @see #getObject
  1135      * @see #getObject
  1146      * @since 1.4
  1136      * @since 1.4
  1147      */
  1137      */
  1148     void setObject(String parameterName, Object x, int targetSqlType)
  1138     void setObject(String parameterName, Object x, int targetSqlType)
  1149         throws SQLException;
  1139         throws SQLException;
  1150 
  1140 
  1151     /**
  1141     /**
  1152      * Sets the value of the designated parameter with the given object.
  1142      * Sets the value of the designated parameter with the given object.
  1153      * The second parameter must be of type <code>Object</code>; therefore, the
       
  1154      * <code>java.lang</code> equivalent objects should be used for built-in types.
       
  1155      *
  1143      *
  1156      * <p>The JDBC specification specifies a standard mapping from
  1144      * <p>The JDBC specification specifies a standard mapping from
  1157      * Java <code>Object</code> types to SQL types.  The given argument
  1145      * Java <code>Object</code> types to SQL types.  The given argument
  1158      * will be converted to the corresponding SQL type before being
  1146      * will be converted to the corresponding SQL type before being
  1159      * sent to the database.
  1147      * sent to the database.
  2495      * this method
  2483      * this method
  2496      * @since 1.7
  2484      * @since 1.7
  2497      */
  2485      */
  2498      public <T> T getObject(String parameterName, Class<T> type) throws SQLException;
  2486      public <T> T getObject(String parameterName, Class<T> type) throws SQLException;
  2499 
  2487 
       
  2488      //------------------------- JDBC 4.2 -----------------------------------
       
  2489 
       
  2490      /**
       
  2491      * <p>Sets the value of the designated parameter with the given object.
       
  2492      *
       
  2493      * If the second argument is an {@code InputStream} then the stream
       
  2494      * must contain the number of bytes specified by scaleOrLength.
       
  2495      * If the second argument is a {@code Reader} then the reader must
       
  2496      * contain the number of characters specified
       
  2497      * by scaleOrLength. If these conditions are not true the driver
       
  2498      * will generate a
       
  2499      * {@code SQLException} when the prepared statement is executed.
       
  2500      *
       
  2501      * <p>The given Java object will be converted to the given targetSqlType
       
  2502      * before being sent to the database.
       
  2503      *
       
  2504      * If the object has a custom mapping (is of a class implementing the
       
  2505      * interface {@code SQLData}),
       
  2506      * the JDBC driver should call the method {@code SQLData.writeSQL} to
       
  2507      * write it to the SQL data stream.
       
  2508      * If, on the other hand, the object is of a class implementing
       
  2509      * {@code Ref}, {@code Blob}, {@code Clob},  {@code NClob},
       
  2510      *  {@code Struct}, {@code java.net.URL},
       
  2511      * or {@code Array}, the driver should pass it to the database as a
       
  2512      * value of the corresponding SQL type.
       
  2513      *
       
  2514      * <p>Note that this method may be used to pass database-specific
       
  2515      * abstract data types.
       
  2516      *<P>
       
  2517      * The default implementation will throw {@code SQLFeatureNotSupportedException}
       
  2518      *
       
  2519      * @param parameterName the name of the parameter
       
  2520      * @param x the object containing the input parameter value
       
  2521      * @param targetSqlType the SQL type to be
       
  2522      * sent to the database. The scale argument may further qualify this type.
       
  2523      * @param scaleOrLength for {@code java.sql.JDBCType.DECIMAL}
       
  2524      *          or {@code java.sql.JDBCType.NUMERIC types},
       
  2525      *          this is the number of digits after the decimal point. For
       
  2526      *          Java Object types {@code InputStream} and {@code Reader},
       
  2527      *          this is the length
       
  2528      *          of the data in the stream or reader.  For all other types,
       
  2529      *          this value will be ignored.
       
  2530      * @exception SQLException if parameterName does not correspond to a named
       
  2531      * parameter; if a database access error occurs
       
  2532      * or this method is called on a closed {@code CallableStatement}  or
       
  2533      *            if the Java Object specified by x is an InputStream
       
  2534      *            or Reader object and the value of the scale parameter is less
       
  2535      *            than zero
       
  2536      * @exception SQLFeatureNotSupportedException if
       
  2537      * the JDBC driver does not support this data type
       
  2538      * @see JDBCType
       
  2539      * @see SQLType
       
  2540      *
       
  2541      * @since 1.8
       
  2542      */
       
  2543      default void setObject(String parameterName, Object x, SQLType targetSqlType,
       
  2544              int scaleOrLength) throws SQLException {
       
  2545         throw new SQLFeatureNotSupportedException("setObject not implemented");
       
  2546     }
       
  2547     /**
       
  2548      * Sets the value of the designated parameter with the given object.
       
  2549      *
       
  2550      * This method is similar to {@link #setObject(String parameterName,
       
  2551      * Object x, SQLType targetSqlType, int scaleOrLength)},
       
  2552      * except that it assumes a scale of zero.
       
  2553      *<P>
       
  2554      * The default implementation will throw {@code SQLFeatureNotSupportedException}
       
  2555      *
       
  2556      * @param parameterName the name of the parameter
       
  2557      * @param x the object containing the input parameter value
       
  2558      * @param targetSqlType the SQL type to be sent to the database
       
  2559      * @exception SQLException if parameterName does not correspond to a named
       
  2560      * parameter; if a database access error occurs
       
  2561      * or this method is called on a closed {@code CallableStatement}
       
  2562      * @exception SQLFeatureNotSupportedException if
       
  2563      * the JDBC driver does not support this data type
       
  2564      * @see JDBCType
       
  2565      * @see SQLType
       
  2566      * @since 1.8
       
  2567      */
       
  2568      default void setObject(String parameterName, Object x, SQLType targetSqlType)
       
  2569         throws SQLException {
       
  2570         throw new SQLFeatureNotSupportedException("setObject not implemented");
       
  2571     }
       
  2572 
       
  2573     /**
       
  2574      * Registers the OUT parameter in ordinal position
       
  2575      * {@code parameterIndex} to the JDBC type
       
  2576      * {@code sqlType}.  All OUT parameters must be registered
       
  2577      * before a stored procedure is executed.
       
  2578      * <p>
       
  2579      * The JDBC type specified by {@code sqlType} for an OUT
       
  2580      * parameter determines the Java type that must be used
       
  2581      * in the {@code get} method to read the value of that parameter.
       
  2582      * <p>
       
  2583      * If the JDBC type expected to be returned to this output parameter
       
  2584      * is specific to this particular database, {@code sqlType}
       
  2585      * may be {@code JDBCType.OTHER} or a {@code SQLType} that is supported by
       
  2586      * the JDBC driver.  The method
       
  2587      * {@link #getObject} retrieves the value.
       
  2588      *<P>
       
  2589      * The default implementation will throw {@code SQLFeatureNotSupportedException}
       
  2590      *
       
  2591      * @param parameterIndex the first parameter is 1, the second is 2,
       
  2592      *        and so on
       
  2593      * @param sqlType the JDBC type code defined by {@code SQLType} to use to
       
  2594      * register the OUT Parameter.
       
  2595      *        If the parameter is of JDBC type {@code JDBCType.NUMERIC}
       
  2596      *        or {@code JDBCType.DECIMAL}, the version of
       
  2597      *        {@code registerOutParameter} that accepts a scale value
       
  2598      *        should be used.
       
  2599      *
       
  2600      * @exception SQLException if the parameterIndex is not valid;
       
  2601      * if a database access error occurs or
       
  2602      * this method is called on a closed {@code CallableStatement}
       
  2603      * @exception SQLFeatureNotSupportedException if
       
  2604      * the JDBC driver does not support this data type
       
  2605      * @see JDBCType
       
  2606      * @see SQLType
       
  2607      * @since 1.8
       
  2608      */
       
  2609     default void registerOutParameter(int parameterIndex, SQLType sqlType)
       
  2610         throws SQLException {
       
  2611         throw new SQLFeatureNotSupportedException("registerOutParameter not implemented");
       
  2612     }
       
  2613 
       
  2614     /**
       
  2615      * Registers the parameter in ordinal position
       
  2616      * {@code parameterIndex} to be of JDBC type
       
  2617      * {@code sqlType}. All OUT parameters must be registered
       
  2618      * before a stored procedure is executed.
       
  2619      * <p>
       
  2620      * The JDBC type specified by {@code sqlType} for an OUT
       
  2621      * parameter determines the Java type that must be used
       
  2622      * in the {@code get} method to read the value of that parameter.
       
  2623      * <p>
       
  2624      * This version of {@code  registrOutParameter} should be
       
  2625      * used when the parameter is of JDBC type {@code JDBCType.NUMERIC}
       
  2626      * or {@code JDBCType.DECIMAL}.
       
  2627      *<P>
       
  2628      * The default implementation will throw {@code SQLFeatureNotSupportedException}
       
  2629      *
       
  2630      * @param parameterIndex the first parameter is 1, the second is 2,
       
  2631      * and so on
       
  2632      * @param sqlType the JDBC type code defined by {@code SQLType} to use to
       
  2633      * register the OUT Parameter.
       
  2634      * @param scale the desired number of digits to the right of the
       
  2635      * decimal point.  It must be greater than or equal to zero.
       
  2636      * @exception SQLException if the parameterIndex is not valid;
       
  2637      * if a database access error occurs or
       
  2638      * this method is called on a closed {@code CallableStatement}
       
  2639      * @exception SQLFeatureNotSupportedException if
       
  2640      * the JDBC driver does not support this data type
       
  2641      * @see JDBCType
       
  2642      * @see SQLType
       
  2643      * @since 1.8
       
  2644      */
       
  2645     default void registerOutParameter(int parameterIndex, SQLType sqlType,
       
  2646             int scale) throws SQLException {
       
  2647         throw new SQLFeatureNotSupportedException("registerOutParameter not implemented");
       
  2648     }
       
  2649     /**
       
  2650      * Registers the designated output parameter.
       
  2651      * This version of
       
  2652      * the method {@code  registrOutParameter}
       
  2653      * should be used for a user-defined or {@code REF} output parameter.
       
  2654      * Examples
       
  2655      * of user-defined types include: {@code STRUCT}, {@code DISTINCT},
       
  2656      * {@code JAVA_OBJECT}, and named array types.
       
  2657      *<p>
       
  2658      * All OUT parameters must be registered
       
  2659      * before a stored procedure is executed.
       
  2660      * <p>  For a user-defined parameter, the fully-qualified SQL
       
  2661      * type name of the parameter should also be given, while a {@code REF}
       
  2662      * parameter requires that the fully-qualified type name of the
       
  2663      * referenced type be given.  A JDBC driver that does not need the
       
  2664      * type code and type name information may ignore it.   To be portable,
       
  2665      * however, applications should always provide these values for
       
  2666      * user-defined and {@code REF} parameters.
       
  2667      *
       
  2668      * Although it is intended for user-defined and {@code REF} parameters,
       
  2669      * this method may be used to register a parameter of any JDBC type.
       
  2670      * If the parameter does not have a user-defined or {@code REF} type, the
       
  2671      * <i>typeName</i> parameter is ignored.
       
  2672      *
       
  2673      * <P><B>Note:</B> When reading the value of an out parameter, you
       
  2674      * must use the getter method whose Java type corresponds to the
       
  2675      * parameter's registered SQL type.
       
  2676      *<P>
       
  2677      * The default implementation will throw {@code SQLFeatureNotSupportedException}
       
  2678      *
       
  2679      * @param parameterIndex the first parameter is 1, the second is 2,...
       
  2680      * @param sqlType the JDBC type code defined by {@code SQLType} to use to
       
  2681      * register the OUT Parameter.
       
  2682      * @param typeName the fully-qualified name of an SQL structured type
       
  2683      * @exception SQLException if the parameterIndex is not valid;
       
  2684      * if a database access error occurs or
       
  2685      * this method is called on a closed {@code CallableStatement}
       
  2686      * @exception SQLFeatureNotSupportedException if
       
  2687      * the JDBC driver does not support this data type
       
  2688      * @see JDBCType
       
  2689      * @see SQLType
       
  2690      * @since 1.8
       
  2691      */
       
  2692     default void registerOutParameter (int parameterIndex, SQLType sqlType,
       
  2693             String typeName) throws SQLException {
       
  2694         throw new SQLFeatureNotSupportedException("registerOutParameter not implemented");
       
  2695     }
       
  2696 
       
  2697     /**
       
  2698      * Registers the OUT parameter named
       
  2699      * <code>parameterName</code> to the JDBC type
       
  2700      * {@code sqlType}.  All OUT parameters must be registered
       
  2701      * before a stored procedure is executed.
       
  2702      * <p>
       
  2703      * The JDBC type specified by {@code sqlType} for an OUT
       
  2704      * parameter determines the Java type that must be used
       
  2705      * in the {@code get} method to read the value of that parameter.
       
  2706      * <p>
       
  2707      * If the JDBC type expected to be returned to this output parameter
       
  2708      * is specific to this particular database, {@code sqlType}
       
  2709      * should be {@code JDBCType.OTHER} or a {@code SQLType} that is supported
       
  2710      * by the JDBC driver..  The method
       
  2711      * {@link #getObject} retrieves the value.
       
  2712      *<P>
       
  2713      * The default implementation will throw {@code SQLFeatureNotSupportedException}
       
  2714      *
       
  2715      * @param parameterName the name of the parameter
       
  2716      * @param sqlType the JDBC type code defined by {@code SQLType} to use to
       
  2717      * register the OUT Parameter.
       
  2718      * If the parameter is of JDBC type {@code JDBCType.NUMERIC}
       
  2719      * or {@code JDBCType.DECIMAL}, the version of
       
  2720      * {@code  registrOutParameter} that accepts a scale value
       
  2721      * should be used.
       
  2722      * @exception SQLException if parameterName does not correspond to a named
       
  2723      * parameter; if a database access error occurs or
       
  2724      * this method is called on a closed {@code CallableStatement}
       
  2725      * @exception SQLFeatureNotSupportedException if
       
  2726      * the JDBC driver does not support this data type
       
  2727      * or if the JDBC driver does not support
       
  2728      * this method
       
  2729      * @since 1.8
       
  2730      * @see JDBCType
       
  2731      * @see SQLType
       
  2732      */
       
  2733     default void registerOutParameter(String parameterName, SQLType sqlType)
       
  2734         throws SQLException {
       
  2735         throw new SQLFeatureNotSupportedException("registerOutParameter not implemented");
       
  2736     }
       
  2737 
       
  2738     /**
       
  2739      * Registers the parameter named
       
  2740      * <code>parameterName</code> to be of JDBC type
       
  2741      * {@code sqlType}.  All OUT parameters must be registered
       
  2742      * before a stored procedure is executed.
       
  2743      * <p>
       
  2744      * The JDBC type specified by {@code sqlType} for an OUT
       
  2745      * parameter determines the Java type that must be used
       
  2746      * in the {@code get} method to read the value of that parameter.
       
  2747      * <p>
       
  2748      * This version of {@code  registrOutParameter} should be
       
  2749      * used when the parameter is of JDBC type {@code JDBCType.NUMERIC}
       
  2750      * or {@code JDBCType.DECIMAL}.
       
  2751      *<P>
       
  2752      * The default implementation will throw {@code SQLFeatureNotSupportedException}
       
  2753      *
       
  2754      * @param parameterName the name of the parameter
       
  2755      * @param sqlType the JDBC type code defined by {@code SQLType} to use to
       
  2756      * register the OUT Parameter.
       
  2757      * @param scale the desired number of digits to the right of the
       
  2758      * decimal point.  It must be greater than or equal to zero.
       
  2759      * @exception SQLException if parameterName does not correspond to a named
       
  2760      * parameter; if a database access error occurs or
       
  2761      * this method is called on a closed {@code CallableStatement}
       
  2762      * @exception SQLFeatureNotSupportedException if
       
  2763      * the JDBC driver does not support this data type
       
  2764      * or if the JDBC driver does not support
       
  2765      * this method
       
  2766      * @since 1.8
       
  2767      * @see JDBCType
       
  2768      * @see SQLType
       
  2769      */
       
  2770     default void registerOutParameter(String parameterName, SQLType sqlType,
       
  2771             int scale) throws SQLException {
       
  2772         throw new SQLFeatureNotSupportedException("registerOutParameter not implemented");
       
  2773     }
       
  2774 
       
  2775     /**
       
  2776      * Registers the designated output parameter.  This version of
       
  2777      * the method {@code  registrOutParameter}
       
  2778      * should be used for a user-named or REF output parameter.  Examples
       
  2779      * of user-named types include: STRUCT, DISTINCT, JAVA_OBJECT, and
       
  2780      * named array types.
       
  2781      *<p>
       
  2782      * All OUT parameters must be registered
       
  2783      * before a stored procedure is executed.
       
  2784      * </p>
       
  2785      * For a user-named parameter the fully-qualified SQL
       
  2786      * type name of the parameter should also be given, while a REF
       
  2787      * parameter requires that the fully-qualified type name of the
       
  2788      * referenced type be given.  A JDBC driver that does not need the
       
  2789      * type code and type name information may ignore it.   To be portable,
       
  2790      * however, applications should always provide these values for
       
  2791      * user-named and REF parameters.
       
  2792      *
       
  2793      * Although it is intended for user-named and REF parameters,
       
  2794      * this method may be used to register a parameter of any JDBC type.
       
  2795      * If the parameter does not have a user-named or REF type, the
       
  2796      * typeName parameter is ignored.
       
  2797      *
       
  2798      * <P><B>Note:</B> When reading the value of an out parameter, you
       
  2799      * must use the {@code getXXX} method whose Java type XXX corresponds to the
       
  2800      * parameter's registered SQL type.
       
  2801      *<P>
       
  2802      * The default implementation will throw {@code SQLFeatureNotSupportedException}
       
  2803      *
       
  2804      * @param parameterName the name of the parameter
       
  2805      * @param sqlType the JDBC type code defined by {@code SQLType} to use to
       
  2806      * register the OUT Parameter.
       
  2807      * @param typeName the fully-qualified name of an SQL structured type
       
  2808      * @exception SQLException if parameterName does not correspond to a named
       
  2809      * parameter; if a database access error occurs or
       
  2810      * this method is called on a closed {@code CallableStatement}
       
  2811      * @exception SQLFeatureNotSupportedException if
       
  2812      * the JDBC driver does not support this data type
       
  2813      * or if the JDBC driver does not support this method
       
  2814      * @see JDBCType
       
  2815      * @see SQLType
       
  2816      * @since 1.8
       
  2817      */
       
  2818     default void registerOutParameter (String parameterName, SQLType sqlType,
       
  2819             String typeName) throws SQLException {
       
  2820         throw new SQLFeatureNotSupportedException("registerOutParameter not implemented");
       
  2821     }
  2500 }
  2822 }