Java Reference
In-Depth Information
}
public void saveBlob(int memberID,String description,byte[] out){
String cmd =
"INSERT INTO Photos (MemberID,Description,Image) VALUES(?,?,?)";
System.out.println(cmd);
try {
Class.forName("com.inet.pool.PoolDriver");
com.inet.tds.TdsDataSource tds = new com.inet.tds.TdsDataSource();
tds.setServerName( "JUPITER" );
tds.setDatabaseName( "MEMBERS" );
tds.setUser( dbUserName );
tds.setPassword( dbPassword );
DataSource ds = tds;
Connection con = ds.getConnection(dbUserName,dbPassword);
PreparedStatement pstmt = con.prepareStatement(cmd);
pstmt.setInt(1, memberID);
pstmt.setString(2, description);
pstmt.setBytes(3, out);
System.out.println(pstmt.executeUpdate());
con.close();
}
catch(ClassNotFoundException e){
e.printStackTrace();
}
catch(SQLException e){
e.printStackTrace();
}
}
}
A Servlet for Downloading Large Objects from a DBMS
The conventional way of incorporating images or other large objects in a Web page is to provide a link
to a disk file and to rely on the operating system to find the file. This works just fine when you have only
a few image files, but in a membership Web site with tens or hundreds of thousands of members, each
of whom may have several photos on file, search times become significant. One way around this is to
design a directory tree, containing hundreds of subdirectories arranged in some logical manner so that
you can navigate rapidly to the right subdirectory.
Letting your DBMS do the work is a much more elegant and attractive way to find the image files. A big
advantage of object relational database management Systems, after all, is that they are designed
specifically for this kind of thing.
Search WWH ::




Custom Search