用Java编写新的Blob [英] Writing to a new Blob in Java

查看:144
本文介绍了用Java编写新的Blob的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够创建一个新的Blob对象,然后对其进行写入.最初,我对此的总体计划如下:

I want to be able to create a new Blob object and then write to it. Originally, my general plan for this was as follows:

创建一个新的Blob(为空,因为没有Blob构造函数) 创建一个新的OutputStream并将其设置为blob.setBinaryStream(0) 写入输出流.

Create a new blob (null, because there's no Blob constructor) Create a new OutputStream and set it to blob.setBinaryStream(0) Write to the output stream.

但是,当我尝试执行此代码时,出现NullPointerException.我应该采取其他方法吗?任何帮助,将不胜感激.

However, I get a NullPointerException when I try to execute this code. Is there a different way I should be going about this? Any help would be appreciated.

谢谢!

〜B

推荐答案

java.sql.Blob是接口而不是类,因此不能存在构造函数.但是您可以实例化实现类SerialBlob,该类允许您从字节数组构造blob.

java.sql.Blob is an interface and not a class, thus no constructor can exist. But you can instantiate the implementing class SerialBlob which allows you to construct a blob from a byte array.

这篇关于用Java编写新的Blob的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆