| 发表于:2007-03-08 17:47:131楼 得分:0 |
import java.io.*;import java.sql.*;import java.util.*;import javax.servlet.*;import javax.servlet.http.*; public class oleextraction { public static void main(string[] args) { try { class.forname( "sun.jdbc.odbc.jdbcodbcdriver "); // set this to a ms access db you have on your machine string filename = "c:/pictures.mdb "; string database = "jdbc:odbc:driver={microsoft access driver (*.mdb)};dbq= "; database+= filename.trim() + ";driverid=22;readonly=true} "; // add on to the end // now we can get the connection from the drivermanager connection con = drivermanager.getconnection( database , " ", " "); statement s = con.createstatement(); s.EXECute( "select employeeid, picture from iddata where employeeid = '00526 ' "); stringbuffer results = new stringbuffer(); resultset rs = s.getresultset(); if (rs != null ) { while ( rs.next() ) { inputstream image = rs.getbinarystream(2); fileoutputstream file = null; file = new fileoutputstream ( "c:/picture.jpg "); int chunk; while ((chunk = image.read()) != -1) file.write(chunk); } } s.close(); } catch (exception e) { system.out.println( "error: " + e); } }} | | |
|