I have a blob column in my database table, for which I have to use byte[] in my Java program as a mapping and to use this data I have to convert it to InputStream or OutputStream. But I don’t know what happens internally when I do so. Can anyone briefly explain me what’s happening when I do this conversion?
I have a blob column in my database table, for which I have to
Share
You create and use byte array I/O streams as follows:
Assuming that you are using a JDBC driver that implements the standard JDBC Blob interface (not all do), you can also connect a
InputStreamorOutputStreamto a blob using thegetBinaryStreamandsetBinaryStreammethods1, and you can also get and set the bytes directly.(In general, you should take appropriate steps to handle any exceptions, and close streams. However, closing
bisandbosin the example above is unnecessary, since they aren’t associated with any external resources; e.g. file descriptors, sockets, database connections.)1 – The
setBinaryStreammethod is really a getter. Go figure.