📄 stringcolumnvti.java
字号:
int count = _columnNames.length; for ( int i = 0; i < count; i++ ) { if ( _columnNames[ i ].equals( columnName ) ) { return i+1; } } throw new SQLException( "Unknown column name." ); } public String getString(int columnIndex) throws SQLException { String columnValue = getRawColumn( columnIndex ); checkNull( columnValue ); return columnValue; } public boolean getBoolean(int columnIndex) throws SQLException { String columnValue = getString( columnIndex ); if ( columnValue == null ) { return false; } else { return Boolean.valueOf( columnValue ).booleanValue(); } } public byte getByte(int columnIndex) throws SQLException { String columnValue = getString( columnIndex ); if ( columnValue == null ) { return (byte) 0; } else { try { return Byte.valueOf( columnValue ).byteValue(); } catch (NumberFormatException e) { throw wrap( e ); } } } public short getShort(int columnIndex) throws SQLException { String columnValue = getString( columnIndex ); if ( columnValue == null ) { return (short) 0; } else { try { return Short.valueOf( columnValue ).shortValue(); } catch (NumberFormatException e) { throw wrap( e ); } } } public int getInt(int columnIndex) throws SQLException { String columnValue = getString( columnIndex ); if ( columnValue == null ) { return 0; } else { try { return Integer.valueOf( columnValue ).intValue(); } catch (NumberFormatException e) { throw wrap( e ); } } } public long getLong(int columnIndex) throws SQLException { String columnValue = getString( columnIndex ); if ( columnValue == null ) { return (long) 0; } else { try { return Long.valueOf( columnValue ).longValue(); } catch (NumberFormatException e) { throw wrap( e ); } } } public float getFloat(int columnIndex) throws SQLException { String columnValue = getString( columnIndex ); if ( columnValue == null ) { return (float) 0; } else { try { return Float.valueOf( columnValue ).floatValue(); } catch (NumberFormatException e) { throw wrap( e ); } } } public double getDouble(int columnIndex) throws SQLException { String columnValue = getString( columnIndex ); if ( columnValue == null ) { return (double) 0; } else { try { return Double.valueOf( columnValue ).doubleValue(); } catch (NumberFormatException e) { throw wrap( e ); } } } public BigDecimal getBigDecimal(int columnIndex) throws SQLException { String columnValue = getString( columnIndex ); if ( columnValue == null ) { return null; } else { try { return new BigDecimal( columnValue ); } catch (NumberFormatException e) { throw wrap( e ); } } } public byte[] getBytes(int columnIndex) throws SQLException { String columnValue = getString( columnIndex ); if ( columnValue == null ) { return null; } else { return columnValue.getBytes(); } } public java.sql.Date getDate(int columnIndex) throws SQLException { String columnValue = getString( columnIndex ); if ( columnValue == null ) { return null; } else { return new Date( parseDateTime( columnValue ) ); } } public java.sql.Time getTime(int columnIndex) throws SQLException { String columnValue = getString( columnIndex ); if ( columnValue == null ) { return null; } else { return new Time( parseDateTime( columnValue ) ); } } public java.sql.Timestamp getTimestamp(int columnIndex) throws SQLException { String columnValue = getString( columnIndex ); if ( columnValue == null ) { return null; } else { return new Timestamp( parseDateTime( columnValue ) ); } } public InputStream getAsciiStream(int columnIndex) throws SQLException { String columnValue = getString( columnIndex ); return getEncodedStream( columnValue, "US-ASCII" ); } public java.io.InputStream getBinaryStream(int columnIndex) throws SQLException { String columnValue = getString( columnIndex ); if ( columnValue == null ) { return null; } else { return new ByteArrayInputStream( getBytes( columnIndex ) ); } } public Blob getBlob(int columnIndex) throws SQLException { String columnValue = getString( columnIndex ); if ( columnValue == null ) { return null; } else { return new SimpleBlob( getBytes( columnIndex ) ); } } public Clob getClob(int columnIndex) throws SQLException { String columnValue = getString( columnIndex ); if ( columnValue == null ) { return null; } { return new SimpleClob( getString( columnIndex ) ); } } /////////////////////////////////////////////////////////////////////////////////// // // PROTECTED BEHAVIOR USED BY SUBCLASSES // /////////////////////////////////////////////////////////////////////////////////// /** * <p> * Return the names of the columns. * </p> */ protected String[] getColumnNames( ) { return _columnNames; } /** * <p> * Set the wasNull flag. * </p> */ protected void setWasNull() { _lastColumnWasNull = true; } /////////////////////////////////////////////////////////////////////////////////// // // PRIVATE MINIONS // /////////////////////////////////////////////////////////////////////////////////// /** * <p> * Set the wasNull flag based on whether this column value turned out to be null. * </p> */ private void checkNull( String columnValue ) { _lastColumnWasNull = ( columnValue == null ); } /** * <p> * Wrap an exception in a SQLException. * </p> */ private SQLException wrap( Throwable t ) { return new SQLException( t.getMessage() ); } /** * <p> * Translate a date/time expression into the corresponding long number of * milliseconds. * </p> */ private long parseDateTime( String columnValue ) throws SQLException { try { DateFormat df = DateFormat.getDateTimeInstance(); java.util.Date rawDate = df.parse( columnValue ); return rawDate.getTime(); } catch (ParseException e) { throw wrap( e ); } } /** * <p> * Turn a string into an appropriately encoded ByteArrayInputStream. * </p> */ private InputStream getEncodedStream( String columnValue, String encoding ) throws SQLException { if ( columnValue == null ) { return null; } else { try { byte[] rawBytes = columnValue.getBytes( encoding ); return new ByteArrayInputStream( rawBytes ); } catch (UnsupportedEncodingException e) { throw wrap( e ); } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -