Saturday, 23 April 2016

Scenario : How do I insert an image file (or other raw data) into a database ?


SCENARIO
How do I insert an image file (or other raw data) into a database ?

All raw data types (including binary documents or images) should be read and uploaded to the database as an array of bytes, byte[].

Originating from a binary file, 
1. Read all data from the file using a FileInputStream.
2. Create a byte array from the read data.

3. Use method setBytes(int index, byte[] data) of java.sql.PreparedStatement to upload the data.

No comments:

Post a Comment

Note: only a member of this blog may post a comment.