From: Christian Mack Date: March 18 1999 4:56pm Subject: Re: INSERTING BLOB Fields in a Table List-Archive: http://lists.mysql.com/mysql/505 Message-Id: <36F13046.563BFAAF@compal.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Josep Curto wrote: > > Hi, > > I use a JAVA Servlet to acces a MySQL DB via a JDBC driver. > All works fine, but now I want to INSERT a BLOB Field with binary data to > the DB, and I can't. > Really, the binary data is a JPG file that I want to put in the DB. > With the SQL String : > "INSERT INTO Fotos (ID_Objecte, Titol, Descripcio, Imatge) VALUES (1,"Name > of Picture","Description","BINARY DATA OF THE JPG FILE")" I get an > error : SQLException from MySQL. > > It only works if the data I INSERT to the LONGBLOB field is text DATA, for > example the contents of a HTML FILE. If the DATA is > BINARY, don't work. > > I've read that I can't LOAD FROM FILE a BLOB Field. I think only SQL > Commands as INSERT INTO and UPDATE are used to add rows to a Table of the > DB. > > My question is, how can I INSERT BINARY DATA to a LONGBLOB Field in a MySQL > DB? Hi Josep This is definitly a mailto:java@stripped question :) To insert binary data via JDBC you need the PreparedStatement with its setBytes() method. Hope this helps. Christian