📄 sqlinputimpl.java
字号:
} //================================================================ // Methods for reading items of SQL user-defined types from the stream. //================================================================ /** * Retrieves the value at the head of this <code>SQLInputImpl</code> * object as an <code>Object</code> in the Java programming language. The * actual type of the object returned is determined by the default * mapping of SQL types to types in the Java programming language unless * there is a custom mapping, in which case the type of the object * returned is determined by this stream's type map. * <P> * The JDBC technology-enabled driver registers a type map with the stream * before passing the stream to the application. * <P> * When the datum at the head of the stream is an SQL <code>NULL</code>, * this method returns <code>null</code>. If the datum is an SQL * structured or distinct type with a custom mapping, this method * determines the SQL type of the datum at the head of the stream, * constructs an object of the appropriate class, and calls the method * <code>SQLData.readSQL</code> on that object. The <code>readSQL</code> * method then calls the appropriate <code>SQLInputImpl.readXXX</code> * methods to retrieve the attribute values from the stream. * * @return the value at the head of the stream as an <code>Object</code> * in the Java programming language; <code>null</code> if * the value is SQL <code>NULL</code> * @throws SQLException if the read position is located at an invalid * position; or if there are no further values in the stream. */ public Object readObject() throws SQLException { Object attrib = (Object)getNextAttribute(); if (attrib == null) { lastValueWasNull = true; return null; } else { lastValueWasNull = false; if (attrib instanceof Struct) { Struct s = (Struct)attrib; // look up the class in the map Class c = (Class)map.get(s.getSQLTypeName()); if (c != null) { // create new instance of the class SQLData obj = null; try { obj = (SQLData)c.newInstance(); } catch (java.lang.InstantiationException ex) { throw new SQLException("Unable to instantiate: " + ex.getMessage()); } catch (java.lang.IllegalAccessException ex) { throw new SQLException("Unable to instantiate: " + ex.getMessage()); } // get the attributes from the struct Object attribs[] = s.getAttributes(map); // create the SQLInput "stream" SQLInputImpl sqlInput = new SQLInputImpl(attribs, map); // read the values... obj.readSQL(sqlInput, s.getSQLTypeName()); return (Object)obj; } } return (Object)attrib; } } /** * Retrieves the value at the head of this <code>SQLInputImpl</code> object * as a <code>Ref</code> object in the Java programming language. * * @return a <code>Ref</code> object representing the SQL * <code>REF</code> value at the head of the stream; if the value * is <code>SQL NULL</code> return <code>null</code> * @throws SQLException if the read position is located at an invalid * position; or if there are no further values in the stream. */ public Ref readRef() throws SQLException { Ref attrib = (Ref)getNextAttribute(); if (attrib == null) { lastValueWasNull = true; return null; } else { lastValueWasNull = false; return attrib; } } /** * Retrieves the <code>BLOB</code> value at the head of this * <code>SQLInputImpl</code> object as a <code>Blob</code> object * in the Java programming language. * <P> * This method does not perform type-safe checking to determine if the * returned type is the expected type as this responsibility is delegated * to the UDT mapping as implemented by a <code>SQLData</code> * implementation. * * @return a <code>Blob</code> object representing the SQL * <code>BLOB</code> value at the head of this stream; * if the value is <code>SQL NULL</code>, return * <code>null</code> * @throws SQLException if the read position is located at an invalid * position; or if there are no further values in the stream. */ public Blob readBlob() throws SQLException { Blob attrib = (Blob)getNextAttribute(); if (attrib == null) { lastValueWasNull = true; return null; } else { lastValueWasNull = false; return attrib; } } /** * Retrieves the <code>CLOB</code> value at the head of this * <code>SQLInputImpl</code> object as a <code>Clob</code> object * in the Java programming language. * <P> * This method does not perform type-safe checking to determine if the * returned type is the expected type as this responsibility is delegated * to the UDT mapping as implemented by a <code>SQLData</code> * implementation. * * @return a <code>Clob</code> object representing the SQL * <code>CLOB</code> value at the head of the stream; * if the value is <code>SQL NULL</code>, return * <code>null</code> * @throws SQLException if the read position is located at an invalid * position; or if there are no further values in the stream. */ public Clob readClob() throws SQLException { Clob attrib = (Clob)getNextAttribute(); if (attrib == null) { lastValueWasNull = true; return null; } else { lastValueWasNull = false; return attrib; } } /** * Reads an SQL <code>ARRAY</code> value from the stream and * returns it as an <code>Array</code> object in the Java programming * language. * <P> * This method does not perform type-safe checking to determine if the * returned type is the expected type as this responsibility is delegated * to the UDT mapping as implemented by a <code>SQLData</code> * implementation. * * @return an <code>Array</code> object representing the SQL * <code>ARRAY</code> value at the head of the stream; * * if the value is <code>SQL NULL</code>, return * <code>null</code> * @throws SQLException if the read position is located at an invalid * position; or if there are no further values in the stream. */ public Array readArray() throws SQLException { Array attrib = (Array)getNextAttribute(); if (attrib == null) { lastValueWasNull = true; return null; } else { lastValueWasNull = false; return attrib; } } /** * Ascertains whether the last value read from this * <code>SQLInputImpl</code> object was <code>null</code>. * * @return <code>true</code> if the SQL value read most recently was * <code>null</code>; otherwise, <code>false</code>; by default it * will return false * @throws SQLException if an error occurs determining the last value * read was a <code>null</code> value or not; */ public boolean wasNull() throws SQLException { return lastValueWasNull; } /** * Reads an SQL <code>DATALINK</code> value from the stream and * returns it as an <code>URL</code> object in the Java programming * language. * <P> * This method does not perform type-safe checking to determine if the * returned type is the expected type as this responsibility is delegated * to the UDT mapping as implemented by a <code>SQLData</code> * implementation. * * @return an <code>URL</code> object representing the SQL * <code>DATALINK</code> value at the head of the stream; * * if the value is <code>SQL NULL</code>, return * <code>null</code> * @throws SQLException if the read position is located at an invalid * position; or if there are no further values in the stream. */ public java.net.URL readURL() throws SQLException { throw new SQLException("Operation not supported"); } //---------------------------- JDBC 4.0 ------------------------- /** * Reads an SQL <code>NCLOB</code> value from the stream and returns it as a * <code>Clob</code> object in the Java programming language. * * @return a <code>NClob</code> object representing data of the SQL <code>NCLOB</code> value * at the head of the stream; <code>null</code> if the value read is * SQL <code>NULL</code> * @exception SQLException if a database access error occurs */ public NClob readNClob() throws SQLException { throw new UnsupportedOperationException("Operation not supported"); } /** * Reads the next attribute in the stream and returns it as a <code>String</code> * in the Java programming language. It is intended for use when * accessing <code>NCHAR</code>,<code>NVARCHAR</code> * and <code>LONGNVARCHAR</code> columns. * * @return the attribute; if the value is SQL <code>NULL</code>, returns <code>null</code> * @exception SQLException if a database access error occurs */ public String readNString() throws SQLException { throw new UnsupportedOperationException("Operation not supported"); } /** * Reads an SQL <code>XML</code> value from the stream and returns it as a * <code>SQLXML</code> object in the Java programming language. * * @return a <code>SQLXML</code> object representing data of the SQL <code>XML</code> value * at the head of the stream; <code>null</code> if the value read is * SQL <code>NULL</code> * @exception SQLException if a database access error occurs */ public SQLXML readSQLXML() throws SQLException { throw new UnsupportedOperationException("Operation not supported"); } /** * Reads an SQL <code>ROWID</code> value from the stream and returns it as a * <code>RowId</code> object in the Java programming language. * * @return a <code>RowId</code> object representing data of the SQL <code>ROWID</code> value * at the head of the stream; <code>null</code> if the value read is * SQL <code>NULL</code> * @exception SQLException if a database access error occurs */ public RowId readRowId() throws SQLException { throw new UnsupportedOperationException("Operation not supported"); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -