日期:2014-05-18  浏览次数:20597 次

jsp中图片存入数据库与读取(源码)
jsp中图片存入数据库与读取(源码)如何实现

------解决方案--------------------
存入数据库(oracle9i)

public void write(){
try {
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
Connection conn = DriverManager.getConnection( "jdbc:oracle:thin:@localhost:1521:tb ", "scott ", " " +
"tiger ");
String fileName = "lib/ojdbc14.jar ";
File f = new File(fileName);
FileInputStream fin = new FileInputStream(f);
// System.out.println( "file size = " + fin.available());
BLOB blob = BLOB.createTemporary(conn, true, BLOB.MODE_READWRITE);
OutputStream out = blob.getBinaryOutputStream();
byte[] data = new byte[(int)fin.available()];
fin.read(data);
out.write(data);
fin.close();
out.close();
PreparedStatement pstmt = conn.prepareStatement( "insert into image values(?,?) ");
pstmt.setString(1,name);
pstmt.setBlob(2, blob);
pstmt.executeUpdate();
pstmt.close();
conn.commit();
conn.close();
} catch (SQLException e) {
System.err.println(e.getMessage());
e.printStackTrace();
} catch (IOException e) {
System.out.println( "1111111111111111111111111111 ");
System.err.println(e.getMessage());
}
}
------解决方案--------------------
jspuploadsmart
------解决方案--------------------
同意2楼
------解决方案--------------------
777
------解决方案--------------------
mark
------解决方案--------------------
可以用这个试试,比较好用,又有文档
commons-fileupload-1.1.1
在apache网上可以下载(是开源的)
------解决方案--------------------
jspuploadsmart


------解决方案--------------------
使用上面几位说的文件上传包 很容易实现的