如何用oracle把值存入oracle数据图片和文本

package com.basicSql.scroll_
import java.io.F
import java.io.FileInputS
import java.io.FileNotFoundE
import java.io.FileOutputS
import java.io.IOE
import java.io.InputS
import java.sql.C
import java.sql.PreparedS
import java.sql.ResultS
import java.sql.SQLE
import com.basicSql.connUtil.C
public class SavePic {
public static Connection conn =
public static PreparedStatement pStmt =
* 数据库中加入图片等文件
public static void InsertPic() {
String sql = "insert into teacher(id,name,photo) values(teacher_seq.nextval,?,?)";
conn = Conndb.connOracle();
pStmt = conn.prepareStatement(sql);
pStmt.setString(1, "signma");
// 数据库插入图片/word/excel等
File f = new File("src/pic.jpg");
FileInputStream fis = new FileInputStream(f);
pStmt.setBinaryStream(2, fis, (int) f.length());
int n = pStmt.executeUpdate();
System.out.println(n + "条记录插入");
} catch (SQLException e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
e.printStackTrace();
} finally {
Conndb.pStmtClose(pStmt);
Conndb.closeConn(conn);
* 从数据库中取出图片等文件
public static void getPic() {
String sql = "select id,name,photo from teacher where id=?";
conn = Conndb.connOracle();
pStmt = conn.prepareStatement(sql);
pStmt.setInt(1, 2);
ResultSet rs = pStmt.executeQuery();
if (rs.next()) {
FileOutputStream fos = new FileOutputStream(new File("abc.jpg"));
InputStream is = rs.getBinaryStream("photo");
byte[] buffer = new byte[4 * 1024];
int length = 0;
while ((length = is.read(buffer)) != -1) {
fos.write(buffer, 0, length);
fos.flush();
fos.close();
is.close();
} catch (SQLException e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
Conndb.pStmtClose(pStmt);
Conndb.closeConn(conn);
阅读(...) 评论()java 保存读取图片到oracle
存入数据库
Connection conn =
ResultSet rs =
Statement stmt =
DBConnectionManager connMgr =
String insertsql = "insert into image (id,pic) values(18,empty_blob())";//首先插入一个空的Blob类型
String updateSql="select fujiannr from T_ZT_MYZJ_MYCJ where id=18 for update";
connMgr = DBConnectionManager.getInstance();
conn = connMgr.getConnection();
conn.setAutoCommit(false);
OutputStream os =
stmt=conn.createStatement();
stmt.executeUpdate(insertsql);
rs=stmt.executeQuery(updateSql);
if (rs.next())
oracle.sql.BLOB blob = (oracle.sql.BLOB) rs.getBlob("fujiannr");
os = blob.getBinaryOutputStream();
InputStream is1= new FileInputStream("c:\\1.png");
int i = 0;
while ((i = is1.read()) != -1) {
os.write(i);
os.flush();
os.close();
catch (Exception e)
e.printStackTrace();
closeAll(rs, stmt,conn);
//失放资源
ClassLoader cl = this.getClass().getClassLoader();
InputStream pro = cl.getResourceAsStream("\\config.properties");
Properties dbProps = new Properties();
dbProps.load(pro);
} catch (Exception e) {
String driverClasses = dbProps.getProperty("dbDriver");
connMgr.freeConnection(driverClasses, conn);
从数据库中读取图片
Connection conn =
ResultSet rs =
Statement stmt =
InputStream issgg =
DBConnectionManager connMgr =
byte bs[] =
connMgr = DBConnectionManager.getInstance();
conn = connMgr.getConnection();
conn.setAutoCommit(false);
stmt=conn.createStatement();
String str = "select pic from image where id=18";
rs=stmt.executeQuery(str);
rs.next();
ob=rs.getBlob(1);
long size = ob.length();
bs = ob.getBytes(1, (int)size);
File file = new File("c:\\" + "image.png");
if (!file.exists())
file.createNewFile(); // 如果文件不存在,则创建
FileOutputStream fos = new FileOutputStream(file);
if (data.length & 0)
fos.write(bs, 0, bs.length);
//while ((size = in.read(bs)) != -1)
fos.write(bs, 0, size);
// in.close();
fos.close();
catch (Exception e)
e.printStackTrace();
closeAll(rs, stmt,conn);
没有更多推荐了,
加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!oracle存入图片和文本(一) - 中华考试网(Examw.Com)
&&当前位置: >
> 文章内容
oracle存入图片和文本(一)&[ 日 ]&【
 说明1:首先所有的文件都是以二进制存储
  2:二进制文件有.doc .xls .jpg
  文本文件有&& .txt .html .xml
  先在oracle数据库中建一张表用与测试
  create table CDL_TEST
  SID& VARCHAR2(20) not null,
  IMG& BLOB,&&&&&& //存储二进制
  DOC& CLOB,&&&& //存储文本
  DATA NUMBER
  -- 约束
  alter table CDL_TEST
  add constraint CDL_SID primary key (SID)
  测试代码如下:
  package DataBaseU
  import java.sql.*;
  import java.util.S
  import java.io.*;
  import oracle.sql.BLOB;
  class InitDB{
  private static Connection con=
  private static Statement stmt=
  private static ResultSet rs=
  InitDB(){
  Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
  String url="jdbc:oracle:thin:@localhost:1521:ORCL";& //ORCL 是sid
  String user="cdl";
  String password="1";
  con= (Connection) DriverManager.getConnection(url,user,password);
  InitDB.setCon(con);
  }catch(Exception e){
  e.printStackTrace();
  public void closCon(){
  con.close();
  }catch(Exception e){
  e.printStackTrace();
  public void stmt(){
  con.close();
  }catch(Exception e){
  e.printStackTrace();
  public void rs(){
  con.close();
  }catch(Exception e){
  e.printStackTrace();
【】【】【】【】
········
  《全国专业技术人员计算机应用能力考试标准教程—word&2003中文字处理》严格根据.. 定价:¥39.50
优惠价:¥29.60&&本书适合报考全国专业技术人员计算机应用能力考试“中文windows&xp操作系统”科目的.. 定价:¥39.50
优惠价:¥29.60&&
············
············
         Copyright ©
() All Rights Reserved10:12 提问
如何将有图片和文字的文章,存进数据库,并取出显示在jsp页面
1.在数据库中 的 “内容”这一个列名,应该设计什么类型?或者该如何设计数据库?
2.如何将有图片和文字的文章内容,存进数据库?
3.如何读取内容到jsp页面?
恳请大佬指教。
按赞数排序
有好的文本编辑插件的,比如百度的uedit等
1.对于mysql数据库,‘内容’数据类型选择text
2.保存的内容就是html代码,图片就是链接,图片先上传到文件服务器,html源码中引入链接地址,文字在html里的格式该怎么编辑怎么编辑
3.jsp展示读取出来的html代码,方法问下度娘
直接存html作为内容。图片单独放在文件系统,文章里存它在服务器上的文件名。
你的需求,就是很多blog,cms系统做的,你可以直接找现成的代码来看。
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!
其他相关推荐怎么将图片和文字同时存入数据库的一个字段内?_百度知道
怎么将图片和文字同时存入数据库的一个字段内?
我想做一个信息发布系统,数据库是oracle,如果我把文字和图片的html代码加一起存在内容这个字段里,该如何才能和保存的时候一样顺序地显示在jsp页面上呢?就像百度贴吧那样。需要javascript吗?有什么好代码示例吗?
我有更好的答案
图片和文字放一个字段里,不可能的,oracle不支持这样干,再说你这样干不科学,图片建议用文件的形式保存在磁盘上,html中只要写文件的路径就可以了。
采纳率:49%
为您推荐:
其他类似问题
数据库的相关知识
换一换
回答问题,赢新手礼包
个人、企业类
违法有害信息,请在下方选择后提交
色情、暴力
我们会通过消息、邮箱等方式尽快将举报结果通知您。

我要回帖

更多关于 word存入oracle 的文章

 

随机推荐