on 2012 Jan 12 4:19 PM
What is the best way to store image in ultraliteJ database? I am going to sync this data with sql server. I have tried long binary datatype to store image but that doesn't work. After the sync the image on sql server is broken. Please let me know if any one has done this.
Here is how to insert data into a LONG BINARY field:
PreparedStatement ps = conn.prepareStatement( "INSERT jdbsblob VALUES(?,?)" ); int cRid = 1; int cVal = 2; java.io.OutputStream ostream; byte[] blob_bytes = new byte[11]; ostream = ps.getBlobOutputStream( cVal ); for (int i = 0; i < blob_bytes.length; i++ ) { blob_bytes[i] = 1; } ostream.write( blob_bytes, 0, rowLens[r] ); ostream.close(); ps.execute();
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You should just be able to change the INSERT statement to an UPDATE:
PreparedStatement ps = conn.prepareStatement( "UPDATE jdbsblob SET col = ? WHERE pk=?" );
Then get a BlobOutputStream for parameter 1 (as the first question mark is the column holding the blob) and write to it, then close(). Finally, call ps.execute().
User | Count |
---|---|
67 | |
10 | |
10 | |
10 | |
10 | |
8 | |
8 | |
7 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.