我正在使用ADF并需要在Carousel中显示图像。在servlet中编写了以下代码,但在页面加载时,它分配值" weblogic.jdbc.wrapper.Blob_oracle_sql_BLOB@xxx 如果数据库中存在针对该特定记录提取的图像,则#blo; (xxx - 某些字母数字值)到blob对象
链接引用 - http://www.baigzeeshan.com/2010/10/display-images-in-carousel-item-in.html
public void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException,
IOException {
response.setContentType(CONTENT_TYPE);
String imageId = request.getParameter("id");
OutputStream os = response.getOutputStream();
Connection conn = null;
try {
Context ctx = new InitialContext();
//Datasource as defined in <res-ref-name> element of weblogic.xml
DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/HrXEDS");
conn = ds.getConnection();
PreparedStatement statement =
conn.prepareStatement("SELECT image_id, image_blob " +
"FROM hr_image_table " +
"WHERE image_id = ?");
statement.setInt(1, new Integer(imageId));
ResultSet rs = statement.executeQuery();
if (rs.next()) {
Blob blob = rs.getBlob("IMAGE_BLOB");
System.out.println("-- blob --" + blob);
BufferedInputStream in =
new BufferedInputStream(blob.getBinaryStream());
int b;
byte[] buffer = new byte[10240];
while ((b = in.read(buffer, 0, 10240)) != -1) {
os.write(buffer, 0, b);
}
os.close();
}
} catch (Exception e) {
System.out.println(e);
} finally {
try {
if (conn != null) {
conn.close();
}
} catch (SQLException sqle) {
System.out.println("SQLException error");
}
}
}
答案 0 :(得分:0)
如果您使用数据源并且Weblogic Server中的配置正在包装数据类型,则可能会出现问题。
在浏览器中打开Weblogic Server管理控制台(服务器:端口/控制台)
转到服务 - &gt;数据来源 - &gt; YourDataSource - &gt;连线投票 - &gt;先进
取消选中属性Wrap Data Types。
希望它有所帮助...