sql = "select tp from gys_sp where id_admin=? and spbm=? FOR UPDATE"; ps = conn.prepareStatement(sql);
ps.setInt(1, _sp.getId());
ps.setString(2, _sp.get_spbm());
rs = ps.executeQuery();
if (rs.next()) {
BLOB blob = (BLOB) rs.getBlob("tp");
OutputStream outStream = ((BLOB) blob)
.getBinaryOutputStream();
System.out.println(_sp.get_file1());
File file = new File(_sp.get_file1());
BufferedInputStream inStream = new BufferedInputStream(
new FileInputStream(file));
byte[] b = new byte[blob.getBufferSize()]; int lenth = 0; while ((lenth = inStream.read(b)) != -1) {
outStream.write(b, 1, lenth);
} inStream.close();
outStream.flush();
outStream.close();
conn.commit();
写是写到里面了.数据也有.不过读的时候.
ps = conn.prepareStatement(sql) ;
ps.setInt(1,id) ;
rs = ps.executeQuery() ;
if (rs.next()) {
blob = ((oracle.jdbc.OracleResultSet)rs).getBLOB("tp");
name = rs.getString("tp_name") ;
InputStream in = blob.getBinaryStream();
// try {
// long nLen = blob.length();
// int nSize = (int) nLen;
// data = new byte[nSize];
// inStream.read(data);
// inStream.close();
// } catch (IOException e) {
//
// System.out.println("获取图片数据失败,原因:" + e.getMessage());
//
// }
out=new FileOutputStream("C:/aaa.jpg");
// long nLen = blob.length();
// int nSize = (int) nLen;
data = new byte[1024];
int bytesRead = 0;
while ((bytesRead=in.read(data))!= -1) {
out.write(data, 0, bytesRead);
}
ps.clearParameters();
in.close() ;
out.close() ;
读出来的图片和原来的图片大小一样.可是打开却什么也没有.为什么?
ps.setInt(1, _sp.getId());
ps.setString(2, _sp.get_spbm());
rs = ps.executeQuery();
if (rs.next()) {
BLOB blob = (BLOB) rs.getBlob("tp");
OutputStream outStream = ((BLOB) blob)
.getBinaryOutputStream();
System.out.println(_sp.get_file1());
File file = new File(_sp.get_file1());
BufferedInputStream inStream = new BufferedInputStream(
new FileInputStream(file));
byte[] b = new byte[blob.getBufferSize()]; int lenth = 0; while ((lenth = inStream.read(b)) != -1) {
outStream.write(b, 1, lenth);
} inStream.close();
outStream.flush();
outStream.close();
conn.commit();
写是写到里面了.数据也有.不过读的时候.
ps = conn.prepareStatement(sql) ;
ps.setInt(1,id) ;
rs = ps.executeQuery() ;
if (rs.next()) {
blob = ((oracle.jdbc.OracleResultSet)rs).getBLOB("tp");
name = rs.getString("tp_name") ;
InputStream in = blob.getBinaryStream();
// try {
// long nLen = blob.length();
// int nSize = (int) nLen;
// data = new byte[nSize];
// inStream.read(data);
// inStream.close();
// } catch (IOException e) {
//
// System.out.println("获取图片数据失败,原因:" + e.getMessage());
//
// }
out=new FileOutputStream("C:/aaa.jpg");
// long nLen = blob.length();
// int nSize = (int) nLen;
data = new byte[1024];
int bytesRead = 0;
while ((bytesRead=in.read(data))!= -1) {
out.write(data, 0, bytesRead);
}
ps.clearParameters();
in.close() ;
out.close() ;
读出来的图片和原来的图片大小一样.可是打开却什么也没有.为什么?
解决方案 »
- (散分)SSH相关问题,请回答,答案有用给分
- struts2 链接进入到下一个页面怎么设置<s:token>
- java通过axis访问.net的web service,传参数后得到的xml结果不正确,xml里没有返回值,但是通过.net测试和服务器本机测试都正确
- validation.xml中 <var-name>fieldJoin</var-name>的值为AND,OR分别是什么意思?
- 一个关于hibernate插入数据的问题。
- 做了一段时间的JSP开发啦,现在想学EJB,请各位指点一二,要从什么地方入手
- jdk 中文文档(或api)
- eclipse中deploy EJB出错!!,答对再加100,帮帮兄弟!!!!
- 权限控制菜单栏,求思路。
- weblogic启动后打不开web页面
- J2EEshih
- <a>标签中HREF=""的 问题
if (rs.next()) {
blob = ((oracle.jdbc.OracleResultSet)rs).getBLOB("tp");
name = rs.getString("tp_name") ;
InputStream in = blob.getBinaryStream();
BufferedInputStream bin = new BufferedInputStream(in) ;
// try {
// long nLen = blob.length();
// int nSize = (int) nLen;
// data = new byte[nSize];
// inStream.read(data);
// inStream.close();
// } catch (IOException e) {
//
// System.out.println("获取图片数据失败,原因:" + e.getMessage());
//
// }
out=new FileOutputStream("C:/aaa.jpg");
// BufferedOutputStream bout = new BufferedOutputStream(out) ;
// long nLen = blob.length();
// int nSize = (int) nLen;
data = new byte[1024];
int bytesRead = 0;
while ((bytesRead=bin.read(data))!= -1) {
out.write(data, 0, bytesRead);
}
ps.clearParameters();
in.close() ;
out.close() ;
}
public static void readPicture() throws Exception
{
Connection conn=null;
PreparedStatement ps=null;
ResultSet rs=null;
String sql="insert into picture values(?)";
File file=new File("D:\\说明文档\\图片\\dc7d2def849cf221adafd51b.jpg");
InputStream in=new BufferedInputStream(new FileInputStream(file));
try
{
conn=SqlManagerSingle.getInstance().getConnection();
ps=conn.prepareStatement(sql);
ps.setBinaryStream(1,in,(int)file.length());
int i=ps.executeUpdate();
System.out.println(i);
} catch (SQLException e)
{
// TODO 自动生成 catch 块
e.printStackTrace();
}
finally
{
SqlManagerSingle.getInstance().free(conn, ps, rs);
in.close();
}
}
public static void writerPicture() throws IOException
{
Connection conn=null;
Statement st=null;
ResultSet rs=null;
String sql="select * from picture";
try
{
conn=SqlManagerSingle.getInstance().getConnection();
st=conn.createStatement();
rs=st.executeQuery(sql);
while(rs.next())
{
InputStream in=rs.getBinaryStream(1);
byte[] bin=new byte[1024];
OutputStream out=new BufferedOutputStream(new FileOutputStream("d:\\dd.jpg"));
for(int i=0;(i=in.read(bin))>0;)
{
out.write(bin, 0, i);
}
in.close();
out.close();
}
} catch (SQLException e)
{
// TODO 自动生成 catch 块
e.printStackTrace();
}
finally
{
SqlManagerSingle.getInstance().free(conn, st, rs);
}
}
我试一个12k和一个1k两张图片.
结果1k没有问题.但是12就有问题了.
是不是和rabbit_liu给你的文件中的初始化有关?
byte[] bin=new byte[1024];
你设置大些再试一下,