import java.sql.*;
import java.io.*;
import java.util.zip.*;
public class JStrPics{ .........................1
public static void getZippedPic(int jpic_num
, byte[][] jpic_data) ..2
throws SQLException, IOException{ ..............3
Connection con = DriverManager.getConnection( ...4
"jdbc:hitachi:PrdbDrive","USER1","PASS1"); .....4
PreparedStatement pstmt = con.prepareStatement ..5
("select p_name,p_data from pics where
p_num = ?"); ....5
pstmt.setInt(1, jpic_num); .....................5
ResultSet rs = pstmt.executeQuery(); .........6
String name; ...................................7
byte[] srcPic; .................................7
while(rs.next()){
name = rs.getString("p_name"); ...............8
srcPic = rs.getBytes("p_data"); ..............9
}
ByteArrayOutputStream baos = new
ByteArrayOutputStream(); .......10
ZipOutputStream zos = new
ZipOutputStream(baos); ..........10
ByteArrayInputStream bais = new
ByteArrayInputStream(srcPic); ...10
ZipEntry ze = new ZipEntry(name); ..............10
zos.putNextEntry(ze); ..........................10
int len = 0; ...................................10
byte[] buff = new byte[1024]; ..................10
while((len = bais.read(buff)) != -1){ ..........10
zos.write(buff, 0, len); .......................10
} .............................................10
zos.closeEntry(); ..............................11
bais.close(); ..................................11
zos.close(); ...................................11
jpic_data[0] = baos.toByteArray(); .............12
baos.close(); ..................................12
return; ........................................13
}
} |