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.

asked 12 Jan '12, 16:19

TEJ's gravatar image

TEJ
31455
accept rate: 0%

Could you tell us how the image is "broken" at SQL Server? For example: - Does the row get to SQL Server? - If so, is there anything at all in the image column for that row? - If so, is it roughly the right length?

(12 Jan '12, 16:24) Tom Slee

Can i extend this code for update

(13 Jan '12, 17:10) TEJ

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();
permanent link

answered 12 Jan '12, 16:37

Tom%20Slee's gravatar image

Tom Slee
1.2k21429
accept rate: 29%

can i extend this code for update query

(13 Jan '12, 17:10) TEJ

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().

(16 Jan '12, 16:27) Tom Slee
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×78

question asked: 12 Jan '12, 16:19

question was seen: 779 times

last updated: 16 Jan '12, 16:27