oralc 中图片的存储与读取
来源:互联网 发布:黛安芬淘宝旗舰店真假 编辑:程序博客网 时间:2024/06/07 16:51
ai0709编写,joker_yao整理
//数据类型 long row
//存储
SaveImg
public void insertr_save_img(String img_no,String imgpath) throws Exception{
PreparedStatement pstmt = null;
try{
File file = new File(imgpath);
int fileLength =(int) file.length();
InputStream fin = new FileInputStream(file);
String query = "Insert into save_img( " +
"img_no, emp_pict"+
" ) values ( "+
"?, ?)";
pstmt = connection.prepareStatement(query);
pstmt.setString(1,img_no);
pstmt.setBinaryStream (2, fin, fileLength);
int affected = pstmt.executeUpdate();
}catch(Exception e){
}
finally {
try{pstmt.close();}catch(Exception e){}
} // try-finally
} // end insert
//读取
Readimg
public byte[] select_img(String emp_no) throws Exception{
PreparedStatement pstmt = null;
byte[] bo;
ResultSet rs = null;
try{
String query = "Select emp_pict " +
" from save_img" +
" where serial_no =? ";
pstmt = connection.prepareStatement(query);
pstmt.setString(1,emp_no);
rs = pstmt.executeQuery();
if(rs.next()) {
bo=rs.getBytes(1);
} // end While
else {
bo=new byte[0];}
} finally {
try{rs.close();}catch(Exception e){}
try{pstmt.close();}catch(Exception e){}
} // try-finally
return bo;
} // end select
//jsp显示
<%
try{
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
String url="jdbc:oracle:thin:@127.0.0.1:1521:oracle? user=scott&password=tiger&useUnicode=true&characterEncoding=8859_1";
Connection conn= DriverManager.getConnection(url);
String sql = "select emp_pict from ee.ba020m where emp_no="+emp_no_imge;
Readimg img= new Readimg(conn);
String img_no="1";
byte[] bo = img.select_img(img_no);
response.reset();
response.setContentType("image/jpeg");
ServletOutputStream sout = response.getOutputStream();
for(int i= 0 ; i< bo.length; i++){
sout.write(bo[i]);
}
sout.flush();
sout.close();
}
catch(Exception e){System.out.println(e);}
finally{
try{rs.close();}catch(Exception e){}
if ( conn!= null ) conn.close();
}
%>
//数据类型 long row
//存储
SaveImg
public void insertr_save_img(String img_no,String imgpath) throws Exception{
PreparedStatement pstmt = null;
try{
File file = new File(imgpath);
int fileLength =(int) file.length();
InputStream fin = new FileInputStream(file);
String query = "Insert into save_img( " +
"img_no, emp_pict"+
" ) values ( "+
"?, ?)";
pstmt = connection.prepareStatement(query);
pstmt.setString(1,img_no);
pstmt.setBinaryStream (2, fin, fileLength);
int affected = pstmt.executeUpdate();
}catch(Exception e){
}
finally {
try{pstmt.close();}catch(Exception e){}
} // try-finally
} // end insert
//读取
Readimg
public byte[] select_img(String emp_no) throws Exception{
PreparedStatement pstmt = null;
byte[] bo;
ResultSet rs = null;
try{
String query = "Select emp_pict " +
" from save_img" +
" where serial_no =? ";
pstmt = connection.prepareStatement(query);
pstmt.setString(1,emp_no);
rs = pstmt.executeQuery();
if(rs.next()) {
bo=rs.getBytes(1);
} // end While
else {
bo=new byte[0];}
} finally {
try{rs.close();}catch(Exception e){}
try{pstmt.close();}catch(Exception e){}
} // try-finally
return bo;
} // end select
//jsp显示
<%
try{
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
String url="jdbc:oracle:thin:@127.0.0.1:1521:oracle? user=scott&password=tiger&useUnicode=true&characterEncoding=8859_1";
Connection conn= DriverManager.getConnection(url);
String sql = "select emp_pict from ee.ba020m where emp_no="+emp_no_imge;
Readimg img= new Readimg(conn);
String img_no="1";
byte[] bo = img.select_img(img_no);
response.reset();
response.setContentType("image/jpeg");
ServletOutputStream sout = response.getOutputStream();
for(int i= 0 ; i< bo.length; i++){
sout.write(bo[i]);
}
sout.flush();
sout.close();
}
catch(Exception e){System.out.println(e);}
finally{
try{rs.close();}catch(Exception e){}
if ( conn!= null ) conn.close();
}
%>
- oralc 中图片的存储与读取
- .NET中二进制图片的存储与读取
- .NET中二进制图片的存储与读取
- .NET中二进制图片的存储与读取
- ASP.NET中二进制图片的存储与读取
- 图片存储与读取
- PHP读取数据库中存储的图片
- Oracle中读取&&存储blob类型存储的图片(待用)
- 黑马程序员学习日记------.NET中二进制图片的存储与读取
- NET二进制图片存储与读取的常见方法
- .NET二进制图片存储与读取的常见方法
- NET二进制图片存储与读取的常见方法
- .NET二进制图片存储与读取的常见方法
- NET二进制图片存储与读取的常见方法
- 多帧Dcm图片的读取与拆分存储
- 读取本地存储的图片
- 图片的存储及读取.
- .NET二进制图片存储与读取
- c# 的拆箱与装箱
- 编译ARM版本时出错误
- 利用宏生成FieldCatalog.
- 万维网之父:语义网或将成为Google终结者
- 算法如功夫——C++ 用递归函数计算n的阶乘n!
- oralc 中图片的存储与读取
- QT相关名词说明
- 在.Net中进行集合运算(使用 Iesi.Collections.dll)
- 牛!Actionscript做的人脸控制
- GRUB命令选择引导操作系统
- MP3/MP4产业的魅族模式和纽曼模式
- 算法如功夫——C++输入两个数求它们的最大公约数
- 学习.net compact framework
- 写下你职业生涯中最难以忘怀的误操作