Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   JAVA (https://www.clubdelphi.com/foros/forumdisplay.php?f=16)
-   -   insertar imagenes a una BD (https://www.clubdelphi.com/foros/showthread.php?t=8958)

seb@ 07-04-2004 14:14:56

insertar imagenes a una BD
 
Hola Foro!!!

Tengo un problema medio urgente!!!, estoy trabajando con una BD Interbase, que me permite ingresar imagenes, pero no se la manera desde JAVA de insertar una imagen X.jpg culaquiera, tambien como hago para borrar una imagen de la BD?

se puede hacer? y cual es la manera?

desde antemano gracias!!!!

santana 07-04-2004 23:39:54

Hola.

Normalmente lo que se hace es pasar la imagen a binario y entonces se inserta en la base de datos. Investiga a partir de ese punto...

No he trabajado nunca con Java / Interbase, te dejo para que te orientes una parte de código extraido del framework Dinamica creado por Martin Cordova. Te aconsejo que le eches un vistazo empezando por la guía de usuario, la verdad es que es muy interesante.



Código:


          /**
          * Save binary file to blob column using a prepared statement.<br>
          * The prepared statement must contain only one dynamic parameter (?),
          * and it must correspond to the BLOB column. Example:<br>
          * insert into images (id, title, imgsize, data) values (1,'my image', 8112, ?)
          * <br><br>
          * This means that the SQL must be pre-processed by your code in order to
          * set the static values. GenericTransaction superclass provides the method getSql()
          * to help you achieve easy static SQL generation.
          * @param sql SQL used to build prepared statement. The blob column will
        * be the only dynamic (?) parameter.
          * @param path File to be uploaded into the blob column
          * @throws Throwable
          */
 
 
        public void saveBlob(String sql, String path) throws Throwable
          {
 
                  /* create buffer to read image data */
                                File f = new File( path );
                                    FileInputStream img = new FileInputStream(f);               
                                int size = (int)f.length();
                                    BufferedInputStream buf = new BufferedInputStream(img,16000);
 
                  /* save image using prepared statement */
                                PreparedStatement p = null;
                         
                                try
                                {
                                    p = _conn.prepareStatement(sql);
                                    p.setBinaryStream(1, buf, size);
                                    p.execute();
                                }
                                catch (Throwable e)
                                {
                                    throw e;
                                }
                                finally
                                {
                                    if (p!=null) p.close();
                                    if (img!=null) img.close();
                                    if (buf!=null) buf.close();
                                }
 
        }

Un saludo.


La franja horaria es GMT +2. Ahora son las 18:17:05.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi