1 17 package org.apache.servicemix.jdbc.adapter; 18 19 import java.io.ByteArrayInputStream ; 20 import java.io.ByteArrayOutputStream ; 21 import java.io.IOException ; 22 import java.io.InputStream ; 23 import java.sql.PreparedStatement ; 24 import java.sql.ResultSet ; 25 import java.sql.SQLException ; 26 27 40 public class StreamJDBCAdapter extends DefaultJDBCAdapter { 41 42 45 protected byte[] getBinaryData(ResultSet rs, int index) throws SQLException { 46 47 try { 48 InputStream is = rs.getBinaryStream(index); 49 ByteArrayOutputStream os = new ByteArrayOutputStream (1024 * 4); 50 51 int ch; 52 while ((ch = is.read()) >= 0) { 53 os.write(ch); 54 } 55 is.close(); 56 os.close(); 57 58 return os.toByteArray(); 59 } catch (IOException e) { 60 throw (SQLException )new SQLException ("Error reading binary parameter: "+index).initCause(e); 61 } 62 } 63 64 67 protected void setBinaryData(PreparedStatement s, int index, byte[] data) throws SQLException { 68 s.setBinaryStream(index, new ByteArrayInputStream (data), data.length); 69 } 70 71 } | Popular Tags |