Ver Mensaje Individual
  #1 (permalink)  
Antiguo 24/10/2014, 14:04
nmenna10
 
Fecha de Ingreso: octubre-2014
Mensajes: 39
Antigüedad: 9 años, 6 meses
Puntos: 0
Pregunta Consulta, insertar en tabla MySQL

Hola, buenas tardes.

Tengo una consulta sobre un metodo que hice para insertar en una tabla.
La misma esta compuesta por datos de texto y una imagen. El problema lo tengo a la hora de insertar la imagen.

este es el error que me da:

Error You have an error in you SQL syntax, check the manual that conrresponds to your MySQL server version fon right syntax to use near '* FROM OPENROWSET (BULK N'C:\Users\\mennani\Pictures\disposicion de papel\2013120.jpg' at line 1


No se como solucionarlo.


Este es el codigo:

Código:
public void nuevoArticulo(String nombre, String descripcion, int stockMinimo, int stockActual,
            Float precio, String ubicacion, Blob imagen, int categoria) {
        
        //METODO PARA GUARDAR UN NUEVO ARTICULO
        
        Connection miConexion = (Connection) ConexionDB.GetConnection();
        String idString;
        try {
            Statement statement = (Statement) miConexion.createStatement();
            Statement statement2 = (Statement) miConexion.createStatement();
            Statement statement3 = (Statement) miConexion.createStatement();            
            
            setNombre(nombre);
            setDescripcion(descripcion);
            setStockMinimo(stockMinimo);
            setStockActual(stockActual);
            setCategoria(categoria);
            setPrecio(precio);
            setImagen(imagen);
            setUbicacion(ubicacion);
            
            ResultSet existe = statement3.executeQuery("select nombre from productos where nombre = '"+jTextField2.getText()+"'");
            if (existe.next()==false){
                //DETERMINO SI ES EL PRIMER REGISTRO O NO
                ResultSet maximo = statement2.executeQuery("select id from productos order by id desc");
                if (maximo.next()==true){ 
                    String idMaximo = maximo.getString("id");
                    int id = Integer.parseInt(idMaximo);
                    id = id + 1; //Si hay articulos cargados me paro en el ultimo ID y le sumo 1
                    idString = Integer.toString(id);
                }else {
                    //SI NO ES EL PRIMERO
                    idString = "1"; //Si la tabla esta vacia el primer ID es 1
                }
                String fot = futuraFoto.getText();
                statement.execute("insert into productos values('" + idString + "','" + nombre + "',"
                        + "'" + descripcion + "','" + stockMinimo + "','" + stockActual + "'"
                        + ",'" + ubicacion + "','" + precio + "','" + categoria + "',"
                        + " * FROM OPENROWSET (BULK N'"+fot+"', medium_blob))");
                //fomratoColumnas();

                JOptionPane.showMessageDialog(jTable1, "Datos ingresados correctamente");
                statement.close();
                statement2.close();
                statement3.close();
                existe.close();
                miConexion.close();
                
            }else {                
                JOptionPane.showMessageDialog(null, "Existe un articulo con ese nombre");                
            }
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(jTable1, "Error " + ex.getMessage());
        } 
    }


Muchas gracias.

Saludos.