发布环境:jdk1.5,tomcat5.5.17,oralce9i
在存储图片的时候,代码如下:
String sqlB = "SELECT photo FROM tcard WHERE cardid=" + cardId +
" FOR UPDATE";
pstmt1 = con.prepareStatement(sqlB);
rs = pstmt1.executeQuery();
BLOB blob = null;
while (rs.next()) {
blob = (BLOB) rs.getBlob("photo");
OutputStream out = blob.getBinaryOutputStream();
// Open the sample file as a stream for insertion into the Blob column
File mapFile = new File(bean.getPhoto());
InputStream sampleFileStream = new FileInputStream(mapFile);
// Buffer to hold chunks of data to being written to the Blob.
byte[] buffer = new byte[50 * 1024];
// Read a chunk of data from the sample file input stream, and write the
// chunk to the Blob column output stream. Repeat till file has been
// fully read.
int nread = 0; // Number of bytes read
while ((nread = sampleFileStream.read(buffer)) != -1) // Read from file
out.write(buffer, 0, nread); // Write to Blob
// Close both streams
sampleFileStream.close();
out.close();
}但是报错提示是:java.lang.ClassCastException:oralce.sql.BLOB
在存储图片的时候,代码如下:
String sqlB = "SELECT photo FROM tcard WHERE cardid=" + cardId +
" FOR UPDATE";
pstmt1 = con.prepareStatement(sqlB);
rs = pstmt1.executeQuery();
BLOB blob = null;
while (rs.next()) {
blob = (BLOB) rs.getBlob("photo");
OutputStream out = blob.getBinaryOutputStream();
// Open the sample file as a stream for insertion into the Blob column
File mapFile = new File(bean.getPhoto());
InputStream sampleFileStream = new FileInputStream(mapFile);
// Buffer to hold chunks of data to being written to the Blob.
byte[] buffer = new byte[50 * 1024];
// Read a chunk of data from the sample file input stream, and write the
// chunk to the Blob column output stream. Repeat till file has been
// fully read.
int nread = 0; // Number of bytes read
while ((nread = sampleFileStream.read(buffer)) != -1) // Read from file
out.write(buffer, 0, nread); // Write to Blob
// Close both streams
sampleFileStream.close();
out.close();
}但是报错提示是:java.lang.ClassCastException:oralce.sql.BLOB
解决方案 »
- myeclipse 配置tomcat中JDK问题
- 初学者求教~JAVA做了一个关于时间的小程序 按钮部分不会~
- 批处理中出现错误: ORA-00913: 值过多.错误如下。
- 我无法将注册信息存储到数据库中,请求帮助急急急!!!
- 刚学java小应用程序,显示问题,老鸟们都进来指定一下呀!!!小弟万分感谢
- 关于在自己的applet类中import其他自定义包类的问题?
- 还是JTable问题.怎样给某一列添加失去和得到焦点事件啊?
- java运行程序的时候可不可以带路径呀?
- 用空的就请进来帮java版一个忙吧!
- JFreeChart生成折线图,如何实现X轴显示自定义值?
- 我是JAVA初学者,问一个弱弱的问题
- 新手请教!
rs.getBlob返回的类型是java.sql.Blob,不能cast为oralce.sql.BLOB