⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sqloutputimpl.java

📁 Mobile 应用程序使用 Java Micro Edition (Java ME) 平台
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * @(#)SQLOutputImpl.java	1.9 06/07/10 * * Copyright 2006 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */package javax.sql.rowset.serial;import java.sql.*;import javax.sql.*;import java.io.*;import java.lang.String;import java.math.*;import java.util.Map;import java.util.Vector;/** * The output stream for writing the attributes of a  * custom-mapped user-defined type (UDT) back to the database.  * The driver uses this interface internally, and its * methods are never directly invoked by an application programmer. * <p> * When an application calls the * method <code>PreparedStatement.setObject</code>, the driver * checks to see whether the value to be written is a UDT with * a custom mapping.  If it is, there will be an entry in a * type map containing the <code>Class</code> object for the * class that implements <code>SQLData</code> for this UDT. * If the value to be written is an instance of <code>SQLData</code>, * the driver will create an instance of <code>SQLOutputImpl</code>  * and pass it to the method <code>SQLData.writeSQL</code>. * The method <code>writeSQL</code> in turn calls the * appropriate <code>SQLOutputImpl.writeXXX</code> methods  * to write data from the <code>SQLData</code> object to * the <code>SQLOutputImpl</code> output stream as the  * representation of an SQL user-defined type. */public class SQLOutputImpl implements SQLOutput {    /**     * A reference to an existing vector that     * contains the attributes of a <code>Struct</code> object.     */    private Vector attribs;    /**     * The type map the driver supplies to a newly created     * <code>SQLOutputImpl</code> object.  This type map     * indicates the <code>SQLData</code> class whose     * <code>writeSQL</code> method will be called.  This     * method will in turn call the appropriate      * <code>SQLOutputImpl</code> writer methods.     */    private Map map;    /**     * Creates a new <code>SQLOutputImpl</code> object     * initialized with the given vector of attributes and     * type map.  The driver will use the type map to determine     * which <code>SQLData.writeSQL</code> method to invoke.     * This method will then call the appropriate     * <code>SQLOutputImpl</code> writer methods in order and     * thereby write the attributes to the new output stream.     *     * @param attributes a <code>Vector</code> object containing the attributes of     *        the UDT to be mapped to one or more objects in the Java      *        programming language     *      * @param map a <code>java.util.Map</code> object containing zero or     *        more entries, with each entry consisting of 1) a <code>String</code>     *        giving the fully qualified name of a UDT and 2) the     *        <code>Class</code> object for the <code>SQLData</code> implementation     *        that defines how the UDT is to be mapped     * @throws SQLException if the <code>attributes</code> or the <code>map</code>     *        is a <code>null</code> value     */    public SQLOutputImpl(Vector<?> attributes, Map<String,?> map)         throws SQLException     {        if ((attributes == null) || (map == null)) {            throw new SQLException("Cannot instantiate a SQLOutputImpl " +            "instance with null parameters");        }                this.attribs = attributes;         this.map = map;    }    //================================================================    // Methods for writing attributes to the stream of SQL data.    // These methods correspond to the column-accessor methods of    // java.sql.ResultSet.    //================================================================        /**     * Writes a <code>String</code> in the Java programming language     * to this <code>SQLOutputImpl</code> object. The driver converts     * it to an SQL <code>CHAR</code>, <code>VARCHAR</code>, or      * <code>LONGVARCHAR</code> before returning it to the database.     *     * @param x the value to pass to the database     * @throws SQLException if the <code>SQLOutputImpl</code> object is in     *        use by a <code>SQLData</code> object attempting to write the attribute     *        values of a UDT to the database.     */    public void writeString(String x) throws SQLException {        //System.out.println("Adding :"+x);        attribs.add(x);    }    /**     * Writes a <code>boolean</code> in the Java programming language     * to this <code>SQLOutputImpl</code> object. The driver converts     * it to an SQL <code>BIT</code> before returning it to the database.     *     * @param x the value to pass to the database          * @throws SQLException if the <code>SQLOutputImpl</code> object is in     *        use by a <code>SQLData</code> object attempting to write the attribute     *        values of a UDT to the database.     */    public void writeBoolean(boolean x) throws SQLException {        attribs.add(new Boolean(x));    }    /**     * Writes a <code>byte</code> in the Java programming language     * to this <code>SQLOutputImpl</code> object. The driver converts     * it to an SQL <code>BIT</code> before returning it to the database.     *     * @param x the value to pass to the database     * @throws SQLException if the <code>SQLOutputImpl</code> object is in     *        use by a <code>SQLData</code> object attempting to write the attribute     *        values of a UDT to the database.     */    public void writeByte(byte x) throws SQLException {        attribs.add(new Byte(x));    }    /**     * Writes a <code>short</code> in the Java programming language     * to this <code>SQLOutputImpl</code> object. The driver converts     * it to an SQL <code>SMALLINT</code> before returning it to the database.     *     * @param x the value to pass to the database          * @throws SQLException if the <code>SQLOutputImpl</code> object is in     *        use by a <code>SQLData</code> object attempting to write the attribute     *        values of a UDT to the database.     */    public void writeShort(short x) throws SQLException {        attribs.add(new Short(x));    }    /**     * Writes an <code>int</code> in the Java programming language     * to this <code>SQLOutputImpl</code> object. The driver converts     * it to an SQL <code>INTEGER</code> before returning it to the database.     *     * @param x the value to pass to the database     * @throws SQLException if the <code>SQLOutputImpl</code> object is in     *        use by a <code>SQLData</code> object attempting to write the attribute     *        values of a UDT to the database.     */    public void writeInt(int x) throws SQLException {        attribs.add(new Integer(x));    }    /**     * Writes a <code>long</code> in the Java programming language     * to this <code>SQLOutputImpl</code> object. The driver converts     * it to an SQL <code>BIGINT</code> before returning it to the database.     *     * @param x the value to pass to the database     * @throws SQLException if the <code>SQLOutputImpl</code> object is in     *        use by a <code>SQLData</code> object attempting to write the attribute     *        values of a UDT to the database.     */    public void writeLong(long x) throws SQLException {        attribs.add(new Long(x));    }    /**     * Writes a <code>float</code> in the Java programming language     * to this <code>SQLOutputImpl</code> object. The driver converts     * it to an SQL <code>REAL</code> before returning it to the database.     *     * @param x the value to pass to the database     * @throws SQLException if the <code>SQLOutputImpl</code> object is in     *        use by a <code>SQLData</code> object attempting to write the attribute     *        values of a UDT to the database.     */    public void writeFloat(float x) throws SQLException {        attribs.add(new Float(x));    }    /**     * Writes a <code>double</code> in the Java programming language     * to this <code>SQLOutputImpl</code> object. The driver converts     * it to an SQL <code>DOUBLE</code> before returning it to the database.     *     * @param x the value to pass to the database     * @throws SQLException if the <code>SQLOutputImpl</code> object is in     *        use by a <code>SQLData</code> object attempting to write the attribute     *        values of a UDT to the database.     */    public void writeDouble(double x) throws SQLException{        attribs.add(new Double(x));    }    /**     * Writes a <code>java.math.BigDecimal</code> object in the Java programming     * language to this <code>SQLOutputImpl</code> object. The driver converts     * it to an SQL <code>NUMERIC</code> before returning it to the database.     *     * @param x the value to pass to the database         * @throws SQLException if the <code>SQLOutputImpl</code> object is in     *        use by a <code>SQLData</code> object attempting to write the attribute     *        values of a UDT to the database.          */    public void writeBigDecimal(java.math.BigDecimal x) throws SQLException{        attribs.add(x);    }    /**     * Writes an array of <code>bytes</code> in the Java programming language     * to this <code>SQLOutputImpl</code> object. The driver converts     * it to an SQL <code>VARBINARY</code> or <code>LONGVARBINARY</code>     * before returning it to the database.     *     * @param x the value to pass to the database       * @throws SQLException if the <code>SQLOutputImpl</code> object is in     *        use by a <code>SQLData</code> object attempting to write the attribute     *        values of a UDT to the database.     */    public void writeBytes(byte[] x) throws SQLException {        attribs.add(x);    }    /**     * Writes a <code>java.sql.Date</code> object in the Java programming     * language to this <code>SQLOutputImpl</code> object. The driver converts     * it to an SQL <code>DATE</code> before returning it to the database.     *     * @param x the value to pass to the database               * @throws SQLException if the <code>SQLOutputImpl</code> object is in     *        use by a <code>SQLData</code> object attempting to write the attribute     *        values of a UDT to the database.     */    public void writeDate(java.sql.Date x) throws SQLException {        attribs.add(x);    }    /**     * Writes a <code>java.sql.Time</code> object in the Java programming     * language to this <code>SQLOutputImpl</code> object. The driver converts     * it to an SQL <code>TIME</code> before returning it to the database.     *     * @param x the value to pass to the database     * @throws SQLException if the <code>SQLOutputImpl</code> object is in     *        use by a <code>SQLData</code> object attempting to write the attribute     *        values of a UDT to the database.     */    public void writeTime(java.sql.Time x) throws SQLException {        attribs.add(x);    }    /**     * Writes a <code>java.sql.Timestamp</code> object in the Java programming     * language to this <code>SQLOutputImpl</code> object. The driver converts     * it to an SQL <code>TIMESTAMP</code> before returning it to the database.     *     * @param x the value to pass to the database     * @throws SQLException if the <code>SQLOutputImpl</code> object is in     *        use by a <code>SQLData</code> object attempting to write the attribute     *        values of a UDT to the database.     */    public void writeTimestamp(java.sql.Timestamp x) throws SQLException {        attribs.add(x);    }    /**     * Writes a stream of Unicode characters to this     * <code>SQLOutputImpl</code> object. The driver will do any necessary     * conversion from Unicode to the database <code>CHAR</code> format.     *     * @param x the value to pass to the database                * @throws SQLException if the <code>SQLOutputImpl</code> object is in     *        use by a <code>SQLData</code> object attempting to write the attribute     *        values of a UDT to the database.     */    public void writeCharacterStream(java.io.Reader x) throws SQLException {         BufferedReader bufReader = new BufferedReader(x);         try {             int i;             while( (i = bufReader.read()) != -1 ) {                char ch = (char)i;		StringBuffer strBuf = new StringBuffer();		strBuf.append(ch);				String str = new String(strBuf);                                String strLine = bufReader.readLine();                                writeString(str.concat(strLine));             }   

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -