java如何上传oracle数据库中的对象

发布于 2024-10-20 19:34:45 字数 241 浏览 1 评论 0原文

我想使用 java 将多个对象上传到我的 Oracle 数据库。

我的对象包括 { DOC, DOCX , PPT , PPTX , PDF } 文件。

如何将我的对象上传到 Oracle 数据库中并从数据库中检索它。

我也有兴趣了解更多关于“如何从 Java 批量插入 Oracle 数据库中的对象列表?”但我认为这个问题之前已经回答过。如果您有任何新的或有趣的资源,请与我分享...

I want to upload multiple objects to my oracle database using java.

My objects included { DOC, DOCX , PPT , PPTX , PDF } files.

How I can upload my objects in oracle database and retrieve it from database.

also I am interested to know more about "How can I batch insert list of objects in Oracle database from Java?" but I think this question answered before. If you have any new or interesting resource please share with me please ...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

深府石板幽径 2024-10-27 19:34:45

插入数据库:

int primaryKeyId = getNextPrimaryKeyId();
PreparedStatement stmt1 = conn.prepareStatement(" insert into docTable values (?, ?, empty_blob()) ");
stmt1.setInt(1, primaryKeyId );
stmt1.setString(2, getDocumentTitle());
stmt1.executeUpdate();

PreparedStatement stmt2 = conn.prepareStatement(" select doc from docTable where id = ? for update ");
stmt2.setInt(1, primaryKeyId);
stmt2.execute();

OracleResultSet rset = (OracleResultSet)stmt2.getResultSet();
if (rset.next()) {
  BLOB document = rset.getBLOB("doc");
  document.trim(0);
  OutputStream os = document.getBinaryOutputStream();
  os.write(getDocumentToBeWrittenToDb());
  os.flush;
  os.close;
}

从数据库读取:

PreparedStatement stmt = conn.prepareStatement(" select title, doc from docTable where id = ?");
stmt.setInt(1, primaryKeyId);
stmt.execute();

BLOB document;
OracleResultSet rset = (OracleResultSet)stmt.getResultSet();

if (rset.next())
{
  ByteArrayOutputStream baos = null;
  InputStream is = null;
  try
  {
    BLOB document = rset.getBLOB("document");
    String title = rset.getString("title");
    is = document.getBinaryStream();
    baos = new ByteArrayOutputStream();
    byte[] data = new byte[2048];
    int len;
    while ((len = is.read(data)) != -1)
    {
      baos.write(data, 0, len);
    }
  } finally
  {
    if (null != baos) baos.close();
    if (null != is) is.close();
  }

  return baos.toByteArray();
}

Insert into db:

int primaryKeyId = getNextPrimaryKeyId();
PreparedStatement stmt1 = conn.prepareStatement(" insert into docTable values (?, ?, empty_blob()) ");
stmt1.setInt(1, primaryKeyId );
stmt1.setString(2, getDocumentTitle());
stmt1.executeUpdate();

PreparedStatement stmt2 = conn.prepareStatement(" select doc from docTable where id = ? for update ");
stmt2.setInt(1, primaryKeyId);
stmt2.execute();

OracleResultSet rset = (OracleResultSet)stmt2.getResultSet();
if (rset.next()) {
  BLOB document = rset.getBLOB("doc");
  document.trim(0);
  OutputStream os = document.getBinaryOutputStream();
  os.write(getDocumentToBeWrittenToDb());
  os.flush;
  os.close;
}

Read from db:

PreparedStatement stmt = conn.prepareStatement(" select title, doc from docTable where id = ?");
stmt.setInt(1, primaryKeyId);
stmt.execute();

BLOB document;
OracleResultSet rset = (OracleResultSet)stmt.getResultSet();

if (rset.next())
{
  ByteArrayOutputStream baos = null;
  InputStream is = null;
  try
  {
    BLOB document = rset.getBLOB("document");
    String title = rset.getString("title");
    is = document.getBinaryStream();
    baos = new ByteArrayOutputStream();
    byte[] data = new byte[2048];
    int len;
    while ((len = is.read(data)) != -1)
    {
      baos.write(data, 0, len);
    }
  } finally
  {
    if (null != baos) baos.close();
    if (null != is) is.close();
  }

  return baos.toByteArray();
}
开始看清了 2024-10-27 19:34:45

如果您

  1. 在 Linux 上运行并且数据库
  2. 版本为 11gR2,并且您已
  3. 在其中创建了 dbfs,并且已
  4. 使用 dbfs_client 挂载它,

则可以像常规网络文件系统一样访问该文件系统。这样做是使用常规文件系统 io 在数据库中存储非结构化数据的最简单方法。 dbfs_client 使用熔断器转换调用。如果需要,您可以稍后创建与其他数据的关系。

罗纳德.

If you are

  1. running on Linux and the database
  2. version is 11gR2 and you have
  3. created a dbfs in it and you have
  4. mounted it using the dbfs_client

you can access the filesystem as a regular networked filesystem. Doing so is the easiest way to store non structured data in the database using regular filesystem io. The dbfs_client translated the calls using fuse. If needed you can create the relations to other data later.

Ronald.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文