Re: encode image for 'setBinaryStream'

From: Gerd Nachtsheim (gerdn_at_users.sourceforge.net)
Date: 07/26/04


Date: Mon, 26 Jul 2004 17:12:29 +0200

Georg Andersson wrote, On 26.07.2004 16:58:

> hi
>
> i like to store small images in a mssql database. i'm using the code
> below for the insert-statement.
>
> PreparedStatement prstmt=connection.prepareStatement("INSERT INTO
> GCP_IMAGE VALUES(?,?,?,?,?,?,?,?");
> prstmt.setLong(1,11);
> prstmt.setShort(2,(short)4);
> prstmt.setBinaryStream(3,fis,(int)file.length());
> prstmt.setString(4,"11_DRAWING.jpg");
> prstmt.setLong(5,file.length());
> prstmt.setString(6,"image/pjpeg");
> prstmt.setNull(7,Types.INTEGER);
> prstmt.setNull(8,Types.INTEGER);
>
> prstmt.execute();
>
> this code returns the foolowing error:java.sql.SQLException:
> [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Line 1:
> Incorrect syntax near '@P8'.

I repeat the answer for your previous posting concerning your syntax error

prstmt.prepareStatement
("INSERT INTO GCP_IMAGE VALUES(?,?,?,?,?,?,?,?)");

you missed the closing parens of the VALUES() part of the INSERT statement.

> after looking through many forums and web-sites, i figured out that i
> would have to encode my image in order to pass the data correctly to
> the database.
>
> has anybody got an idea how i'm supposed to do that?

I am not sure about the encoding, you better first try with the correct
syntax.

HTH

gerd

-- 
Gerd Nachtsheim mailto:gerdn@users.sourceforge.net ICQ:#13126958


Relevant Pages

  • encode image for setBinaryStream
    ... i like to store small images in a mssql database. ... below for the insert-statement. ... PreparedStatement prstmt=connection.prepareStatement("INSERT INTO ...
    (comp.lang.java.databases)
  • Re: conditional inclusion of pictures
    ... every time I unlock, I find my syntax has changed to the following: ... Here's my syntax, just as you said except that I moved the images into a new ... > the airline so that if Emirates is selected then the Emirates logo ...
    (microsoft.public.word.mailmerge.fields)
  • Re: conditional inclusion of pictures
    ... my syntax is no longer changing since I unchecked ... I am still dealing with the issue of images not showing up. ... Airline selected in Dropdown1 ... the airline so that if Emirates is selected then the Emirates logo ...
    (microsoft.public.word.mailmerge.fields)
  • Re: conditional inclusion of pictures
    ... Peter Jamieson ... my syntax is no longer changing since I unchecked ... I am still dealing with the issue of images not showing up. ... ran a test in a new word document with the dropdown1 field which contains: ...
    (microsoft.public.word.mailmerge.fields)
  • Re: Supporting multiple database
    ... I have an app that needs to connect to either - an Access database, MySql ... database or MsSql database. ... MySql and realise that there are syntax issues between these two back ...
    (microsoft.public.dotnet.languages.vb)