Code example for PreparedStatement

Methods: setBytes

0
     */ 
    @SuppressWarnings("fallthrough") 
    @Override 
    public void setJDBCObject(PreparedStatement stmt, int index, PyObject object, int type)
        throws SQLException { 
        if (DataHandler.checkNull(stmt, index, object, type)) {
            return; 
        } 
 
        switch (type) {
 
            case Types.CLOB:
                if (object instanceof PyFile) {
                    object = ((PyFile) object).read();
                } 
 
                String clob = (String) object.__tojava__(String.class);
                int length = clob.length();
                InputStream stream = new ByteArrayInputStream(StringUtil.toBytes(clob));
 
                stream = new BufferedInputStream(stream);
 
                stmt.setBinaryStream(index, stream, length);
 
                // Reader reader = new StringReader(clob); 
                // reader = new BufferedReader(reader); 
                // stmt.setCharacterStream(index, reader, length); 
                break; 
 
            case Types.BLOB:
                byte[] lob = null;
                Object jobject = null;
 
                if (object instanceof PyFile) {
                    jobject = object.__tojava__(InputStream.class);
                } else { 
                    jobject = object.__tojava__(Object.class);
                } 
 
                // it really is unfortunate that I need to send the length of the stream 
                if (jobject instanceof InputStream) {
                    lob = read((InputStream) jobject);
                } else if (jobject instanceof byte[]) {
                    lob = (byte[]) jobject;
                } 
 
                if (lob != null) {
                    stmt.setBytes(index, lob);
                    break; 
                } 
            default : 
                super.setJDBCObject(stmt, index, object, type);
                break; 
        } 
    } 
 
    /**