急!Oracle中的Blob字段中的内容如何在JSP中显示??

ice_girl 2002-05-21 05:53:58
问题起源于我做的JSP版网上考试系统,需要Oracle中的Blob字段存储试题,以弥补文本框不能存储特殊字符和图片的缺点,但是如何将其取出来,并且在JSP中显示???
有谁解决过类似的问题?感谢赐教!!!!
...全文
5 点赞 收藏 5
写回复
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
kaitty 2002-05-23
再给一段代码,可能对你有帮助。
Connection connection = ds.getConnection();
connection.setReadOnly(false);
Statement statement = connection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
ResultSet results = statement.executeQuery(SQLString);
results.setFetchDirection(ResultSet.FETCH_UNKNOWN);

if(results !=null)
{
while (results.next())
{
Blob blob = results.getBlob("Blob_Field_Name");
FileInputStream instream = new FileInputStream("F:\\someImage.jpg");
int length = instream.available();
byte[] buf = new byte[length];
instream.read(buf);
results.updateBytes("Blob_Field_Name", buf);
results.updateRow();
instream.close();
}
}
回复
kaitty 2002-05-23
可以直接用Blob aBlob = rs.getBlob(2);
回复
ice_girl 2002-05-21
BLOB blob = (BLOB)((OracleResultSet)rset).getBlob(2);
出现错误:
The method oracle.jdbc.driver.OracleBlob getBlob(int) declared in class oracle.jdbc.driver.OracleResultSet cannot override the method of the same signature declared in interface java.sql.ResultSet. They must have the same return type.
package org.apache.jsp;

Why?
回复
ice_girl 2002-05-21
谢谢,我马上试一试!
回复
kaitty 2002-05-21
The following code will do what you want once you have got hold of your file as a file.


conn.setAutoCommit(false);
String prepare = "insert into news_xml values(" + id + ", empty_blob())";
String cmd = "SELECT * FROM news_xml where id=" + id + " for update";
Statement stmt = conn.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
stmt.executeUpdate(prepare);
ResultSet rset = stmt.executeQuery(cmd);
rset.next();
BLOB blob = (BLOB)((OracleResultSet)rset).getBlob(2);
FileInputStream instream = new FileInputStream(f);
OutputStream outstream = blob.getBinaryOutputStream();
int size = blob.getBufferSize();
byte[] buffer = new byte[size];
int length = -1;
while ((length = instream.read(buffer)) != -1) outstream.write(buffer, 0, length);
instream.close();
outstream.close();
conn.commit();

要在jsp中显示把
while ((length = instream.read(buffer)) != -1)
out.print(buffer);


回复
发动态
发帖子
Web 开发
创建于2007-09-28

7.9w+

社区成员

Java Web 开发
申请成为版主
社区公告
暂无公告