Blob对象读取出来后是乱码?
bjblz 2004-01-04 02:05:07 代码如下:
<%@ page contentType="text/html; charset=gb2312" %>
<jsp:useBean id="blobtest" class="blobBean.BlobBean" scope="page"/>
<%@ page import="publicBean.*"%>
<%@ page import="java.sql.*"%>
<%@ page import="javax.sql.*"%>
<%@ page import="java.io.*"%>
<%@page import="oracle.jdbc.driver.OracleResultSet"%>
<%@page import="oracle.sql.BLOB"%>
<%
try
{
// blobtest.addBlob("c:\\blz.JPG");
// blobtest.readBlob("c:\\blz.JPG");
// out.println("sucess!");
DBConnect dbc = new DBConnect();
dbc.getConnection().setAutoCommit(false);
//Statement stmt = conn.createStatement();
ResultSet rset = dbc.executeQuery("SELECT blobvalue FROM blobtable where rownum=1");
BLOB blob = null;
while (rset.next()) {
blob = ((OracleResultSet) rset).getBLOB(1);
System.out.println(blob.length());
}
//FileOutputStream file_out = new FileOutputStream(new File(fileName));
InputStream blob_in = blob.getBinaryStream();
int temp;
while((temp=blob_in.read())!=-1){
out.write(temp);//读取数据、写入文件系统
}
out.close();
blob_in.close();
dbc.getConnection().commit();
}
catch(Exception e)
{
out.println(e);
e.printStackTrace();
}
%>