Search in sources :

Example 6 with Blob

use of java.sql.Blob in project jdk8u_jdk by JetBrains.

the class BaseRowSetTests method testAdvancedParameters.

/*
     * DataProvider used to set advanced parameters for types that are supported
     */
@DataProvider(name = "testAdvancedParameters")
private Object[][] testAdvancedParameters() throws SQLException {
    byte[] bytes = new byte[10];
    Ref aRef = new SerialRef(new StubRef("INTEGER", query));
    Array aArray = new SerialArray(new StubArray("INTEGER", new Object[1]));
    Blob aBlob = new SerialBlob(new StubBlob());
    Clob aClob = new SerialClob(new StubClob());
    Reader rdr = new StringReader(query);
    InputStream is = new StringBufferInputStream(query);
    ;
    brs = new StubBaseRowSet();
    brs.setBytes(1, bytes);
    brs.setAsciiStream(2, is, query.length());
    brs.setRef(3, aRef);
    brs.setArray(4, aArray);
    brs.setBlob(5, aBlob);
    brs.setClob(6, aClob);
    brs.setBinaryStream(7, is, query.length());
    brs.setUnicodeStream(8, is, query.length());
    brs.setCharacterStream(9, rdr, query.length());
    return new Object[][] { { 1, bytes }, { 2, is }, { 3, aRef }, { 4, aArray }, { 5, aBlob }, { 6, aClob }, { 7, is }, { 8, is }, { 9, rdr } };
}
Also used : SerialArray(javax.sql.rowset.serial.SerialArray) StubBlob(util.StubBlob) SerialBlob(javax.sql.rowset.serial.SerialBlob) Blob(java.sql.Blob) StringBufferInputStream(java.io.StringBufferInputStream) InputStream(java.io.InputStream) Reader(java.io.Reader) StringReader(java.io.StringReader) SerialBlob(javax.sql.rowset.serial.SerialBlob) StubClob(util.StubClob) StubBlob(util.StubBlob) SerialClob(javax.sql.rowset.serial.SerialClob) StubRef(util.StubRef) StubArray(util.StubArray) Array(java.sql.Array) SerialArray(javax.sql.rowset.serial.SerialArray) StubRef(util.StubRef) SerialRef(javax.sql.rowset.serial.SerialRef) Ref(java.sql.Ref) StringBufferInputStream(java.io.StringBufferInputStream) StringReader(java.io.StringReader) StubBaseRowSet(util.StubBaseRowSet) SerialRef(javax.sql.rowset.serial.SerialRef) Clob(java.sql.Clob) StubClob(util.StubClob) SerialClob(javax.sql.rowset.serial.SerialClob) StubArray(util.StubArray) DataProvider(org.testng.annotations.DataProvider)

Example 7 with Blob

use of java.sql.Blob in project adempiere by adempiere.

the class GridTable method readData.

//	setDeleteable
/**************************************************************************
	 *	Read Data from Recordset
	 *  @param rs result set
	 *  @return Data Array
	 */
private Object[] readData(ResultSet rs) {
    int size = m_fields.size();
    Object[] rowData = new Object[size];
    String columnName = null;
    int displayType = 0;
    //	Types see also MField.createDefault
    try {
        //	get row data
        for (int j = 0; j < size; j++) {
            //	Column Info
            GridField field = (GridField) m_fields.get(j);
            columnName = field.getColumnName();
            displayType = field.getDisplayType();
            //	Integer, ID, Lookup (UpdatedBy is a numeric column)
            if (displayType == DisplayType.Integer || (DisplayType.isID(displayType) && (columnName.endsWith("_ID") || columnName.endsWith("_Acct") || columnName.equals("AD_Key") || columnName.equals("AD_Display"))) || columnName.endsWith("atedBy")) {
                //	Integer
                rowData[j] = new Integer(rs.getInt(j + 1));
                if (rs.wasNull())
                    rowData[j] = null;
            } else //	Number
            if (DisplayType.isNumeric(displayType))
                //	BigDecimal
                rowData[j] = rs.getBigDecimal(j + 1);
            else //	Date
            if (DisplayType.isDate(displayType))
                //	Timestamp
                rowData[j] = rs.getTimestamp(j + 1);
            else //	RowID or Key (and Selection)
            if (displayType == DisplayType.RowID)
                rowData[j] = null;
            else //	YesNo
            if (displayType == DisplayType.YesNo) {
                String str = rs.getString(j + 1);
                if (field.isEncryptedColumn())
                    str = (String) decrypt(str);
                //	Boolean
                rowData[j] = new Boolean("Y".equals(str));
            } else //	LOB
            if (DisplayType.isLOB(displayType)) {
                Object value = rs.getObject(j + 1);
                if (rs.wasNull())
                    rowData[j] = null;
                else if (value instanceof Clob) {
                    Clob lob = (Clob) value;
                    long length = lob.length();
                    rowData[j] = lob.getSubString(1, (int) length);
                } else if (value instanceof Blob) {
                    Blob lob = (Blob) value;
                    long length = lob.length();
                    rowData[j] = lob.getBytes(1, (int) length);
                } else if (value instanceof String)
                    rowData[j] = value;
                else if (value instanceof byte[])
                    rowData[j] = value;
            } else
                //	String
                //	String
                rowData[j] = rs.getString(j + 1);
            //	Encrypted
            if (field.isEncryptedColumn() && displayType != DisplayType.YesNo)
                rowData[j] = decrypt(rowData[j]);
        }
    } catch (SQLException e) {
        log.log(Level.SEVERE, columnName + ", DT=" + displayType, e);
    }
    return rowData;
}
Also used : Blob(java.sql.Blob) SQLException(java.sql.SQLException) Clob(java.sql.Clob)

Example 8 with Blob

use of java.sql.Blob in project adempiere by adempiere.

the class PO method get_LOB.

//	getFindParameter
/**************************************************************************
	 * 	Load LOB
	 * 	@param value LOB
	 * 	@return object
	 */
private Object get_LOB(Object value) {
    log.fine("Value=" + value);
    if (value == null)
        return null;
    //
    Object retValue = null;
    long length = -99;
    try {
        //[ 1643996 ] Chat not working in postgres port
        if (value instanceof String || value instanceof byte[])
            retValue = value;
        else if (//	returns String
        value instanceof Clob) {
            Clob clob = (Clob) value;
            length = clob.length();
            retValue = clob.getSubString(1, (int) length);
        } else if (//	returns byte[]
        value instanceof Blob) {
            Blob blob = (Blob) value;
            length = blob.length();
            //	correct
            int index = 1;
            if (blob.getClass().getName().equals("oracle.jdbc.rowset.OracleSerialBlob"))
                //	Oracle Bug Invalid Arguments
                index = 0;
            //	at oracle.jdbc.rowset.OracleSerialBlob.getBytes(OracleSerialBlob.java:130)
            retValue = blob.getBytes(index, (int) length);
        } else
            log.log(Level.SEVERE, "Unknown: " + value);
    } catch (Exception e) {
        log.log(Level.SEVERE, "Length=" + length, e);
    }
    return retValue;
}
Also used : Blob(java.sql.Blob) Clob(java.sql.Clob) Savepoint(java.sql.Savepoint) SQLException(java.sql.SQLException) DBException(org.adempiere.exceptions.DBException) AdempiereException(org.adempiere.exceptions.AdempiereException)

Example 9 with Blob

use of java.sql.Blob in project adempiere by adempiere.

the class WMediaDialog method createMedia.

//  displayData
private AMedia createMedia() throws SQLException {
    AMedia media;
    String contentType = null;
    if (m_data instanceof byte[]) {
        media = new AMedia(this.getTitle(), null, contentType, (byte[]) m_data);
    } else if (m_data instanceof Blob) {
        media = new AMedia(this.getTitle(), null, contentType, ((Blob) m_data).getBinaryStream());
    } else if (m_data instanceof Clob) {
        Clob clob = (Clob) m_data;
        long length = clob.length() > 100 ? 100 : clob.length();
        String data = ((Clob) m_data).getSubString(1, new Long(length).intValue());
        if (data.toUpperCase().indexOf("<html>") >= 0) {
            contentType = "text/html";
        } else {
            contentType = "text/plain";
        }
        media = new AMedia(this.getTitle(), null, contentType, ((Clob) m_data).getCharacterStream());
    } else {
        contentType = "text/plain";
        media = new AMedia(this.getTitle(), null, contentType, m_data.toString());
    }
    return media;
}
Also used : Blob(java.sql.Blob) AMedia(org.zkoss.util.media.AMedia) Clob(java.sql.Clob)

Example 10 with Blob

use of java.sql.Blob in project cubrid-manager by CUBRID.

the class CUBRIDConnectionProxyTest method methodCreateBlob.

/**
	 * Test method for
	 * {@link com.cubrid.jdbc.proxy.driver.CUBRIDConnectionProxy#createBlob()} .
	 */
public void methodCreateBlob(CUBRIDConnectionProxy conn) throws SQLException {
    Blob blob = conn.createBlob();
    assertNotNull(blob);
}
Also used : Blob(java.sql.Blob)

Aggregations

Blob (java.sql.Blob)337 ResultSet (java.sql.ResultSet)130 SQLException (java.sql.SQLException)109 PreparedStatement (java.sql.PreparedStatement)106 InputStream (java.io.InputStream)97 Clob (java.sql.Clob)81 ByteArrayInputStream (java.io.ByteArrayInputStream)59 IOException (java.io.IOException)54 Statement (java.sql.Statement)52 Connection (java.sql.Connection)36 Test (org.junit.Test)34 BigDecimal (java.math.BigDecimal)25 Timestamp (java.sql.Timestamp)25 SQLXML (java.sql.SQLXML)22 OutputStream (java.io.OutputStream)21 NClob (java.sql.NClob)21 Reader (java.io.Reader)19 Date (java.sql.Date)18 ArrayList (java.util.ArrayList)17 List (java.util.List)17