将图片上传到数据库问题!

lilylucy 2003-11-18 02:36:20
各位,谁有将图片上传到数据库的实例,烦请略说一二,一定要加个注释哦,因为我不会,谢谢!数据库用的是Oracle.
...全文
28 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
yxc369 2003-11-18
  • 打赏
  • 举报
回复
/**
* 将文件写入数据库
* @param pathname:文件全路径
*/
public void writeDBFromFile(String pathname){
myFile=new File(pathname);
try{
//将文件转化为文件流
java.io.FileInputStream fis=new FileInputStream(myFile);
//得到一个数据库连接
con=new DbConnect().getConnection("test","123","jdbc:odbc:kdc145");
pst=con.prepareStatement("update test set mblob=? where id=2");
//pst.setInt(1,2);
byte bb[];
String sql="ab";
bb=sql.getBytes();
pst.setBinaryStream(1,new java.io.ByteArrayInputStream(bb),bb.length);
//pst.setBinaryStream(1,fis,(int)myFile.length());
pst.executeUpdate();
}catch(Exception e){
System.out.println(e.toString());
}finally{
try{
if (rs!=null) rs.close();
if (pst!=null) pst.close();
if (con!=null) con.close();

}catch(Exception e){
System.out.println(e.toString());
}
}
}
数据库是 oracle,通过jdbc连接
hanty 2003-11-18
  • 打赏
  • 举报
回复
JSPSMART中不是有一个现成例子嘛

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧