save photo in 2 different tables java oracle database

0

I am 2 days ago trying to save a photo in 2 different tables of a database, the weird thing is that in the first table it saves the image but in the second one, I do not pass the code:

@Override
    public void GrabarFoto(InputStream uploadedInputStream, FormDataContentDisposition fileDetail) throws SQLException {



        String detalleArchivo = fileDetail.getFileName();
        String[] partes = detalleArchivo.split("_", 2);             
        String data2 = partes[1];
        String[] parts = data2.split("\.");
        System.out.println("registro"+ partes[0]+"licencia o dni"+parts[0]);

        String ACMNRO = partes[0];
        String tipoImagen = parts[0];

        PreparedStatement stmt = null;
        Connection dbConnection = null;
        try {
            dbConnection = Conexion.obtenerConexion();

            if(tipoImagen.equals(LICENCIA)) {
                stmt = dbConnection.prepareStatement(
                        "UPDATE ACTACAMINERA SET ACMFOTOLICENCIA=? where ACMNRO=? ");
            }else {
                stmt = dbConnection.prepareStatement(
                        "UPDATE ACTACAMINERA SET ACMFOTODNI=? where ACMNRO=? ");
            }


            stmt.setBinaryStream(1, uploadedInputStream);
            stmt.setString(2, ACMNRO);
            stmt.executeUpdate();



        } catch (SQLException e) {

            e.printStackTrace();
        }finally{

              try{
                 if(stmt!=null)
                     dbConnection.close();
              }catch(SQLException se){
              }
              try{
                 if(dbConnection!=null)
                     dbConnection.close();
              }catch(SQLException se){
                 se.printStackTrace();
              }
           }
        int OJTID= obtenerObjetoId(ACMNRO);
        guardarObjetoDescriptivo(OJTID,uploadedInputStream,tipoImagen);

    }

    private void guardarObjetoDescriptivo(int oJTID, InputStream uploadedInputStream, String tipoImagen) {
        PreparedStatement stmt = null;
        Connection dbConnection = null;
        try {
            dbConnection = Conexion.obtenerConexion();


            if(tipoImagen.equals(LICENCIA)) {
                stmt = dbConnection.prepareStatement("UPDATE OBJETO_DATOS_DESCRIPTIVOS SET ODDFOTOLICENCIA=? where OJTID=?");
            }else {
                stmt = dbConnection.prepareStatement("UPDATE OBJETO_DATOS_DESCRIPTIVOS SET ODDFOTODNI=? where OJTID=?");

            }

            stmt.setBinaryStream(1, uploadedInputStream);
            stmt.setInt(2, oJTID);
            stmt.executeUpdate();
            System.out.println("aquiiiiiiiiii"+oJTID);


        } catch (SQLException e) {

            e.printStackTrace();
        }finally{

              try{
                 if(stmt!=null)
                     dbConnection.close();
              }catch(SQLException se){
              }
              try{
                 if(dbConnection!=null)
                     dbConnection.close();
              }catch(SQLException se){
                 se.printStackTrace();
              }
           }

    }

    private int obtenerObjetoId(String aCMNRO) throws SQLException {
        PreparedStatement  stmt =null;
        Connection dbConnection = null;
        int OJTID = 0;

        try {
            dbConnection = Conexion.obtenerConexion();
            stmt = dbConnection.prepareStatement("select * from OBJETOS where OJTIDENTIFICADOR1= ?");
            stmt.setString(1, aCMNRO);

            ResultSet rs = stmt.executeQuery();
            while (rs.next()) {
                OJTID=rs.getInt("OJTID");
            }

        } catch (Exception e) {
            throw e;
        } finally {
             try{
                 if(stmt!=null)
                     dbConnection.close();
              }catch(SQLException se){
              }
              try{
                 if(dbConnection!=null)
                     dbConnection.close();
              }catch(SQLException se){
                 se.printStackTrace();
              }
        }
        return OJTID;
    }

The method "recordFoto" saves the image perfectly, then I call the method "obtainObjectId" that gets me the id of the table which also returns the correct id, finally the method where I am having the problem is in the "saveObjectDescriptive" where I do not throw any kind of error but I do not save the photo in the registry, could someone give me a hand with this please? Thank you very much already.

    
asked by Gaston de la cruz 02.02.2018 в 12:28
source

0 answers