1 18 package org.apache.activemq.store.jdbc.adapter; 19 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 import org.apache.activemq.util.ByteArrayInputStream; 28 29 42 public class StreamJDBCAdapter extends DefaultJDBCAdapter { 43 44 47 protected byte[] getBinaryData(ResultSet rs, int index) throws SQLException { 48 49 try { 50 InputStream is = rs.getBinaryStream(index); 51 ByteArrayOutputStream os = new ByteArrayOutputStream (1024 * 4); 52 53 int ch; 54 while ((ch = is.read()) >= 0) { 55 os.write(ch); 56 } 57 is.close(); 58 os.close(); 59 60 return os.toByteArray(); 61 } catch (IOException e) { 62 throw (SQLException )new SQLException ("Error reading binary parameter: "+index).initCause(e); 63 } 64 } 65 66 69 protected void setBinaryData(PreparedStatement s, int index, byte[] data) throws SQLException { 70 s.setBinaryStream(index, new ByteArrayInputStream(data), data.length); 71 } 72 73 } 74 | Popular Tags |