如何将 zip 文件移动到 Java 中的 blob 列?
我有一个 Java 程序,它创建许多 xml 文件,然后将它们压缩并保存到文件系统中。稍后在程序中,我想将同一个 zip 文件放入 Oracle 数据库的 blob 列中。问题是我不知道该怎么做。我不需要读取它或对数据执行任何操作,只需将其移动到数据库以进行持久的中央存储。
谢谢!
I have a Java program that creates a number of xml file and then zips them up and saves them to the file system. Later in the program I want to put that same zip file into a blob column of my oracle database. Problem is I'm not sure how to do that. I don't need to read it or do anything with the data, just move it to the database for persistent, central storage.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有多种方法可以做到这一点,但PreparedStatement.setBinaryStream可能是最好的方法。
(请注意,为了简单起见,我没有包含任何关闭
Connection
、PreparedStatement
和InputStream
所需的 try/catch 内容,但是您需要这样做。)通过这种方式,数据将从文件流式传输到数据库,而不必一次全部加载到内存中。
There are several ways you can do this, but
PreparedStatement.setBinaryStream
is probably the best way.(Note that for simplicity I didn't include any of the necessary try/catch stuff for closing the
Connection
,PreparedStatement
andInputStream
, but you would need to do that.)Done this way, the data will be streamed from the file to the database without having to be loaded in to memory all at once.
我认为您正在寻找使用
setBytes()
方法:因此,表示电子邮件的表的示例(其中正文是字节流)如下所示:
我假设您可以轻松地为您的压缩 XML 对象转换调用
getBytes()
。I think you're looking to use the
setBytes()
method :So an example for a table representing e-mails where the body is a stream of bytes would look like:
I'm assuming you can easily convert call
getBytes()
for your Zipped XML object.