Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/java/sql/SQLOutput.java
38829 views
/*1* Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package java.sql;2627/**28* The output stream for writing the attributes of a user-defined29* type back to the database. This interface, used30* only for custom mapping, is used by the driver, and its31* methods are never directly invoked by a programmer.32* <p>When an object of a class implementing the interface33* <code>SQLData</code> is passed as an argument to an SQL statement, the34* JDBC driver calls the method <code>SQLData.getSQLType</code> to35* determine the kind of SQL36* datum being passed to the database.37* The driver then creates an instance of <code>SQLOutput</code> and38* passes it to the method <code>SQLData.writeSQL</code>.39* The method <code>writeSQL</code> in turn calls the40* appropriate <code>SQLOutput</code> <i>writer</i> methods41* <code>writeBoolean</code>, <code>writeCharacterStream</code>, and so on)42* to write data from the <code>SQLData</code> object to43* the <code>SQLOutput</code> output stream as the44* representation of an SQL user-defined type.45* @since 1.246*/4748public interface SQLOutput {4950//================================================================51// Methods for writing attributes to the stream of SQL data.52// These methods correspond to the column-accessor methods of53// java.sql.ResultSet.54//================================================================5556/**57* Writes the next attribute to the stream as a <code>String</code>58* in the Java programming language.59*60* @param x the value to pass to the database61* @exception SQLException if a database access error occurs62* @exception SQLFeatureNotSupportedException if the JDBC driver does not support63* this method64* @since 1.265*/66void writeString(String x) throws SQLException;6768/**69* Writes the next attribute to the stream as a Java boolean.70* Writes the next attribute to the stream as a <code>String</code>71* in the Java programming language.72*73* @param x the value to pass to the database74* @exception SQLException if a database access error occurs75* @exception SQLFeatureNotSupportedException if the JDBC driver does not support76* this method77* @since 1.278*/79void writeBoolean(boolean x) throws SQLException;8081/**82* Writes the next attribute to the stream as a Java byte.83* Writes the next attribute to the stream as a <code>String</code>84* in the Java programming language.85*86* @param x the value to pass to the database87* @exception SQLException if a database access error occurs88* @exception SQLFeatureNotSupportedException if the JDBC driver does not support89* this method90* @since 1.291*/92void writeByte(byte x) throws SQLException;9394/**95* Writes the next attribute to the stream as a Java short.96* Writes the next attribute to the stream as a <code>String</code>97* in the Java programming language.98*99* @param x the value to pass to the database100* @exception SQLException if a database access error occurs101* @exception SQLFeatureNotSupportedException if the JDBC driver does not support102* this method103* @since 1.2104*/105void writeShort(short x) throws SQLException;106107/**108* Writes the next attribute to the stream as a Java int.109* Writes the next attribute to the stream as a <code>String</code>110* in the Java programming language.111*112* @param x the value to pass to the database113* @exception SQLException if a database access error occurs114* @exception SQLFeatureNotSupportedException if the JDBC driver does not support115* this method116* @since 1.2117*/118void writeInt(int x) throws SQLException;119120/**121* Writes the next attribute to the stream as a Java long.122* Writes the next attribute to the stream as a <code>String</code>123* in the Java programming language.124*125* @param x the value to pass to the database126* @exception SQLException if a database access error occurs127* @exception SQLFeatureNotSupportedException if the JDBC driver does not support128* this method129* @since 1.2130*/131void writeLong(long x) throws SQLException;132133/**134* Writes the next attribute to the stream as a Java float.135* Writes the next attribute to the stream as a <code>String</code>136* in the Java programming language.137*138* @param x the value to pass to the database139* @exception SQLException if a database access error occurs140* @exception SQLFeatureNotSupportedException if the JDBC driver does not support141* this method142* @since 1.2143*/144void writeFloat(float x) throws SQLException;145146/**147* Writes the next attribute to the stream as a Java double.148* Writes the next attribute to the stream as a <code>String</code>149* in the Java programming language.150*151* @param x the value to pass to the database152* @exception SQLException if a database access error occurs153* @exception SQLFeatureNotSupportedException if the JDBC driver does not support154* this method155* @since 1.2156*/157void writeDouble(double x) throws SQLException;158159/**160* Writes the next attribute to the stream as a java.math.BigDecimal object.161* Writes the next attribute to the stream as a <code>String</code>162* in the Java programming language.163*164* @param x the value to pass to the database165* @exception SQLException if a database access error occurs166* @exception SQLFeatureNotSupportedException if the JDBC driver does not support167* this method168* @since 1.2169*/170void writeBigDecimal(java.math.BigDecimal x) throws SQLException;171172/**173* Writes the next attribute to the stream as an array of bytes.174* Writes the next attribute to the stream as a <code>String</code>175* in the Java programming language.176*177* @param x the value to pass to the database178* @exception SQLException if a database access error occurs179* @exception SQLFeatureNotSupportedException if the JDBC driver does not support180* this method181* @since 1.2182*/183void writeBytes(byte[] x) throws SQLException;184185/**186* Writes the next attribute to the stream as a java.sql.Date object.187* Writes the next attribute to the stream as a <code>java.sql.Date</code> object188* in the Java programming language.189*190* @param x the value to pass to the database191* @exception SQLException if a database access error occurs192* @exception SQLFeatureNotSupportedException if the JDBC driver does not support193* this method194* @since 1.2195*/196void writeDate(java.sql.Date x) throws SQLException;197198/**199* Writes the next attribute to the stream as a java.sql.Time object.200* Writes the next attribute to the stream as a <code>java.sql.Date</code> object201* in the Java programming language.202*203* @param x the value to pass to the database204* @exception SQLException if a database access error occurs205* @exception SQLFeatureNotSupportedException if the JDBC driver does not support206* this method207* @since 1.2208*/209void writeTime(java.sql.Time x) throws SQLException;210211/**212* Writes the next attribute to the stream as a java.sql.Timestamp object.213* Writes the next attribute to the stream as a <code>java.sql.Date</code> object214* in the Java programming language.215*216* @param x the value to pass to the database217* @exception SQLException if a database access error occurs218* @exception SQLFeatureNotSupportedException if the JDBC driver does not support219* this method220* @since 1.2221*/222void writeTimestamp(java.sql.Timestamp x) throws SQLException;223224/**225* Writes the next attribute to the stream as a stream of Unicode characters.226*227* @param x the value to pass to the database228* @exception SQLException if a database access error occurs229* @exception SQLFeatureNotSupportedException if the JDBC driver does not support230* this method231* @since 1.2232*/233void writeCharacterStream(java.io.Reader x) throws SQLException;234235/**236* Writes the next attribute to the stream as a stream of ASCII characters.237*238* @param x the value to pass to the database239* @exception SQLException if a database access error occurs240* @exception SQLFeatureNotSupportedException if the JDBC driver does not support241* this method242* @since 1.2243*/244void writeAsciiStream(java.io.InputStream x) throws SQLException;245246/**247* Writes the next attribute to the stream as a stream of uninterpreted248* bytes.249*250* @param x the value to pass to the database251* @exception SQLException if a database access error occurs252* @exception SQLFeatureNotSupportedException if the JDBC driver does not support253* this method254* @since 1.2255*/256void writeBinaryStream(java.io.InputStream x) throws SQLException;257258//================================================================259// Methods for writing items of SQL user-defined types to the stream.260// These methods pass objects to the database as values of SQL261// Structured Types, Distinct Types, Constructed Types, and Locator262// Types. They decompose the Java object(s) and write leaf data263// items using the methods above.264//================================================================265266/**267* Writes to the stream the data contained in the given268* <code>SQLData</code> object.269* When the <code>SQLData</code> object is <code>null</code>, this270* method writes an SQL <code>NULL</code> to the stream.271* Otherwise, it calls the <code>SQLData.writeSQL</code>272* method of the given object, which273* writes the object's attributes to the stream.274* The implementation of the method <code>SQLData.writeSQL</code>275* calls the appropriate <code>SQLOutput</code> writer method(s)276* for writing each of the object's attributes in order.277* The attributes must be read from an <code>SQLInput</code>278* input stream and written to an <code>SQLOutput</code>279* output stream in the same order in which they were280* listed in the SQL definition of the user-defined type.281*282* @param x the object representing data of an SQL structured or283* distinct type284* @exception SQLException if a database access error occurs285* @exception SQLFeatureNotSupportedException if the JDBC driver does not support286* this method287* @since 1.2288*/289void writeObject(SQLData x) throws SQLException;290291/**292* Writes an SQL <code>REF</code> value to the stream.293*294* @param x a <code>Ref</code> object representing data of an SQL295* <code>REF</code> value296* @exception SQLException if a database access error occurs297* @exception SQLFeatureNotSupportedException if the JDBC driver does not support298* this method299* @since 1.2300*/301void writeRef(Ref x) throws SQLException;302303/**304* Writes an SQL <code>BLOB</code> value to the stream.305*306* @param x a <code>Blob</code> object representing data of an SQL307* <code>BLOB</code> value308*309* @exception SQLException if a database access error occurs310* @exception SQLFeatureNotSupportedException if the JDBC driver does not support311* this method312* @since 1.2313*/314void writeBlob(Blob x) throws SQLException;315316/**317* Writes an SQL <code>CLOB</code> value to the stream.318*319* @param x a <code>Clob</code> object representing data of an SQL320* <code>CLOB</code> value321*322* @exception SQLException if a database access error occurs323* @exception SQLFeatureNotSupportedException if the JDBC driver does not support324* this method325* @since 1.2326*/327void writeClob(Clob x) throws SQLException;328329/**330* Writes an SQL structured type value to the stream.331*332* @param x a <code>Struct</code> object representing data of an SQL333* structured type334*335* @exception SQLException if a database access error occurs336* @exception SQLFeatureNotSupportedException if the JDBC driver does not support337* this method338* @since 1.2339*/340void writeStruct(Struct x) throws SQLException;341342/**343* Writes an SQL <code>ARRAY</code> value to the stream.344*345* @param x an <code>Array</code> object representing data of an SQL346* <code>ARRAY</code> type347*348* @exception SQLException if a database access error occurs349* @exception SQLFeatureNotSupportedException if the JDBC driver does not support350* this method351* @since 1.2352*/353void writeArray(Array x) throws SQLException;354355//--------------------------- JDBC 3.0 ------------------------356357/**358* Writes a SQL <code>DATALINK</code> value to the stream.359*360* @param x a <code>java.net.URL</code> object representing the data361* of SQL DATALINK type362*363* @exception SQLException if a database access error occurs364* @exception SQLFeatureNotSupportedException if the JDBC driver does not support365* this method366* @since 1.4367*/368void writeURL(java.net.URL x) throws SQLException;369370//--------------------------- JDBC 4.0 ------------------------371372/**373* Writes the next attribute to the stream as a <code>String</code>374* in the Java programming language. The driver converts this to a375* SQL <code>NCHAR</code> or376* <code>NVARCHAR</code> or <code>LONGNVARCHAR</code> value377* (depending on the argument's378* size relative to the driver's limits on <code>NVARCHAR</code> values)379* when it sends it to the stream.380*381* @param x the value to pass to the database382* @exception SQLException if a database access error occurs383* @exception SQLFeatureNotSupportedException if the JDBC driver does not support384* this method385* @since 1.6386*/387void writeNString(String x) throws SQLException;388389/**390* Writes an SQL <code>NCLOB</code> value to the stream.391*392* @param x a <code>NClob</code> object representing data of an SQL393* <code>NCLOB</code> value394*395* @exception SQLException if a database access error occurs396* @exception SQLFeatureNotSupportedException if the JDBC driver does not support397* this method398* @since 1.6399*/400void writeNClob(NClob x) throws SQLException;401402403/**404* Writes an SQL <code>ROWID</code> value to the stream.405*406* @param x a <code>RowId</code> object representing data of an SQL407* <code>ROWID</code> value408*409* @exception SQLException if a database access error occurs410* @exception SQLFeatureNotSupportedException if the JDBC driver does not support411* this method412* @since 1.6413*/414void writeRowId(RowId x) throws SQLException;415416417/**418* Writes an SQL <code>XML</code> value to the stream.419*420* @param x a <code>SQLXML</code> object representing data of an SQL421* <code>XML</code> value422*423* @throws SQLException if a database access error occurs,424* the <code>java.xml.transform.Result</code>,425* <code>Writer</code> or <code>OutputStream</code> has not been closed for the <code>SQLXML</code> object or426* if there is an error processing the XML value. The <code>getCause</code> method427* of the exception may provide a more detailed exception, for example, if the428* stream does not contain valid XML.429* @exception SQLFeatureNotSupportedException if the JDBC driver does not support430* this method431* @since 1.6432*/433void writeSQLXML(SQLXML x) throws SQLException;434435//--------------------------JDBC 4.2 -----------------------------436437/**438* Writes to the stream the data contained in the given object. The439* object will be converted to the specified targetSqlType440* before being sent to the stream.441*<p>442* When the {@code object} is {@code null}, this443* method writes an SQL {@code NULL} to the stream.444* <p>445* If the object has a custom mapping (is of a class implementing the446* interface {@code SQLData}),447* the JDBC driver should call the method {@code SQLData.writeSQL} to448* write it to the SQL data stream.449* If, on the other hand, the object is of a class implementing450* {@code Ref}, {@code Blob}, {@code Clob}, {@code NClob},451* {@code Struct}, {@code java.net.URL},452* or {@code Array}, the driver should pass it to the database as a453* value of the corresponding SQL type.454*<P>455* The default implementation will throw {@code SQLFeatureNotSupportedException}456*457* @param x the object containing the input parameter value458* @param targetSqlType the SQL type to be sent to the database.459* @exception SQLException if a database access error occurs or460* if the Java Object specified by x is an InputStream461* or Reader object and the value of the scale parameter is less462* than zero463* @exception SQLFeatureNotSupportedException if464* the JDBC driver does not support this data type465* @see JDBCType466* @see SQLType467* @since 1.8468*/469default void writeObject(Object x, SQLType targetSqlType) throws SQLException {470throw new SQLFeatureNotSupportedException();471}472473}474475476477