Пример #1
1
  /**
   * Determine the type of attachment, based on file extension, and add it to the elog entry with
   * the entry_id.
   *
   * @param fname input filename, either an image or a text file
   * @param fileType "I" for image file, "A" for text file
   * @param entry_id ID of entry to which to add this file
   * @param caption Caption or 'title' for the attachment
   * @throws Exception
   */
  private void addFileToElog(
      final String fname, String fileType, final int entry_id, final String caption)
      throws Exception {
    // Get the file extension
    final int ndx = fname.lastIndexOf(".");
    final String extension = fname.substring(ndx + 1);
    long fileTypeID = getFileTypeId(fileType, extension);

    // If the image type cannot be found in the RDB, change its file type to
    // an attachment and look for the
    // extension as an attachment
    if (fileTypeID == -1 && fileType.equals("I")) {
      fileType = "A";
      fileTypeID = getFileTypeId(fileType, extension);
    }

    // Initiate the sql to add attachments to the elog
    final String mysql = "call logbook.logbook_pkg.add_entry_attachment" + "(?, ?, ?, ?, ?)";
    final Connection connection = rdb.getConnection();
    final CallableStatement statement = connection.prepareCall(mysql);
    try {
      statement.setInt(1, entry_id);
      statement.setString(2, fileType);
      statement.setString(3, caption);
      statement.setLong(4, fileTypeID);
      final File inputFile = new File(fname);

      // Send the image to the sql.
      if (fileType.equals("I")) {
        try {
          final int file_size = (int) inputFile.length();
          final FileInputStream input_stream = new FileInputStream(inputFile);
          statement.setBinaryStream(5, input_stream, file_size);
          input_stream.close();
        } catch (FileNotFoundException e1) {
          System.out.println("Could not find " + fname);
          return;
        }
      }
      // Send the text attachment to the sql
      else {
        // Create a Blob to store the attachment in.
        final BLOB blob = BLOB.createTemporary(connection, true, BLOB.DURATION_SESSION);
        blob.setBytes(1L, getBytesFromFile(inputFile));
        statement.setBlob(5, blob);
      }
      statement.executeQuery();
    } finally {
      statement.close();
    }
  }
 public void setBinaryStream(String parameterName, InputStream x, int length) throws SQLException {
   checkOpen();
   try {
     _stmt.setBinaryStream(parameterName, x, length);
   } catch (SQLException e) {
     handleException(e);
   }
 }
 public void setBinaryStream(String parameterName, InputStream inputStream) throws SQLException {
   checkOpen();
   try {
     ((CallableStatement) _stmt).setBinaryStream(parameterName, inputStream);
   } catch (SQLException e) {
     handleException(e);
   }
 }
Пример #4
0
  public String guardarDato(PublicacionesDTO asistenciacursosDTO) {
    try {
      try {
        ConexionBD conexionBD = new ConexionBD();
        conexionBD.abrir();
        Connection connection = conexionBD.getConexion();

        String sql = "{ ? = call insertar_publicaciones(?,?,?,?,?,?,?,?)} ";

        CallableStatement callableStatement = connection.prepareCall(sql);
        callableStatement.registerOutParameter(1, Types.INTEGER);
        callableStatement.setString(2, asistenciacursosDTO.getPeriodo());
        callableStatement.setString(3, asistenciacursosDTO.getPublicacion());
        callableStatement.setString(4, asistenciacursosDTO.getInstitucion());
        callableStatement.setBinaryStream(5, asistenciacursosDTO.getEvidencia().getInputstream());
        callableStatement.setInt(6, asistenciacursosDTO.getIdmodif());
        Calendar cal1 = Calendar.getInstance();
        String Fecha =
            (""
                + cal1.get(Calendar.DATE)
                + "/"
                + cal1.get(Calendar.MONTH)
                + "/"
                + cal1.get(Calendar.YEAR)
                + " "
                + cal1.get(Calendar.HOUR_OF_DAY)
                + ":"
                + cal1.get(Calendar.MINUTE)
                + ":"
                + cal1.get(Calendar.SECOND)
                + ":"
                + cal1.get(Calendar.MILLISECOND));
        callableStatement.setString(7, Fecha);
        callableStatement.setInt(8, asistenciacursosDTO.getIdlic());
        callableStatement.setInt(9, asistenciacursosDTO.getIdusuario());

        callableStatement.execute();
        Integer num = callableStatement.getInt(1);
        connection.close();
        if (num == 1) {

          return "¡Se guardo satisfactoriamente!";

        } else {
          return "";
        }

      } catch (Exception e) {
        e.printStackTrace();
      }
    } catch (Exception ex) {
      System.out.println("Error en.." + ex.getMessage());
    }

    return "";
  }
Пример #5
0
  /** Sets the binaryStream */
  @Override
  public void setBinaryStream(String parameterName, InputStream x, int length) throws SQLException {
    try {
      _cstmt.setBinaryStream(parameterName, x, length);
    } catch (SQLException e) {
      onSqlException(e);

      throw e;
    } catch (RuntimeException e) {
      onRuntimeException(e);

      throw e;
    }
  }
Пример #6
0
  public String ActualizarEvidencia(PublicacionesDTO publicacionesDTO, int idUsuMod) {
    try {
      try {
        ConexionBD conexionBD = new ConexionBD();
        conexionBD.abrir();
        Connection connection = conexionBD.getConexion();

        String sql = "{ ? = call actualizar_evidencia_publicaciones(?,?,?,?)} ";

        CallableStatement callableStatement = connection.prepareCall(sql);
        callableStatement.registerOutParameter(1, Types.INTEGER);
        callableStatement.setInt(2, publicacionesDTO.getId());
        callableStatement.setInt(3, idUsuMod);
        Calendar cal1 = Calendar.getInstance();
        String Fecha =
            (""
                + cal1.get(Calendar.DATE)
                + "/"
                + cal1.get(Calendar.MONTH)
                + "/"
                + cal1.get(Calendar.YEAR)
                + " "
                + cal1.get(Calendar.HOUR_OF_DAY)
                + ":"
                + cal1.get(Calendar.MINUTE)
                + ":"
                + cal1.get(Calendar.SECOND)
                + ":"
                + cal1.get(Calendar.MILLISECOND));
        callableStatement.setString(4, Fecha);
        callableStatement.setBinaryStream(5, publicacionesDTO.getEvidencia().getInputstream());
        callableStatement.execute();
        Integer num = callableStatement.getInt(1);
        connection.close();
        if (num == 1) {
          return "¡Se actualizo satisfactoriamente!";
        } else {
          return "";
        }
      } catch (Exception e) {
        e.printStackTrace();
      }
    } catch (Exception ex) {
      System.out.println("Error en ActualizarEvidencia()..." + ex.getMessage());
    }

    return "";
  }
Пример #7
0
  /** @see java.sql.PreparedStatement#setBinaryStream(int, java.io.InputStream, int) */
  public void setBinaryStream(int parameterIndex, InputStream x, int length) throws SQLException {

    original.setBinaryStream(parameterIndex, x, length);
  }
Пример #8
0
  /** @see java.sql.CallableStatement#setBinaryStream(java.lang.String, java.io.InputStream, int) */
  public void setBinaryStream(String parameterName, InputStream x, int length) throws SQLException {

    original.setBinaryStream(parameterName, x, length);
  }
 public void setBinaryStream(String parameterName, InputStream x, long length)
     throws SQLException {
   passThru.setBinaryStream(parameterName, x, length);
 }
Пример #10
0
 public void bind(VariableTable vt) throws java.sql.SQLException {
   int rows;
   Object val;
   try {
     stmt.clearParameters();
   } catch (java.sql.SQLException sqle) {
   }
   if (paramNames.length > 0) {
     for (rows = 0; rows < paramNames.length; rows++) {
       val = vt.getValue(paramNames[rows]);
       if (paramTypes[rows].equals("IN")) {
         if (val == null) stmt.setNull(rows + 1, 1);
         else {
           if (vt.getType(paramNames[rows]) != java.sql.Types.LONGVARCHAR
               && vt.getType(paramNames[rows]) != java.sql.Types.LONGVARBINARY)
             stmt.setObject(rows + 1, val);
           else if (vt.getType(paramNames[rows]) == java.sql.Types.LONGVARCHAR) {
             java.io.StringReader long_var = new java.io.StringReader(val.toString());
             stmt.setCharacterStream(rows + 1, long_var, 16384);
             // long_var.close();
           } else if (vt.getType(paramNames[rows]) == java.sql.Types.LONGVARBINARY) {
             java.io.File os_file = new java.io.File(val.toString());
             if (os_file.exists() && os_file.isFile() && os_file.canRead()) {
               try {
                 java.io.FileInputStream long_var = new java.io.FileInputStream(os_file);
                 stmt.setBinaryStream(rows + 1, long_var, 16384);
                 // long_var.close();
               } catch (java.io.IOException ioe) {
               }
             } else stmt.setNull(rows + 1, 1);
           }
         }
       } else if (paramTypes[rows].equals("OUT")) {
         stmt.registerOutParameter(rows + 1, vt.getType(paramNames[rows]));
       } else if (paramTypes[rows].equals("INOUT")) {
         if (val == null) stmt.setNull(rows + 1, 1);
         else {
           if (vt.getType(paramNames[rows]) != java.sql.Types.LONGVARCHAR
               && vt.getType(paramNames[rows]) != java.sql.Types.LONGVARBINARY)
             stmt.setObject(rows + 1, val);
           else if (vt.getType(paramNames[rows]) != java.sql.Types.LONGVARCHAR) {
             java.io.StringReader long_var = new java.io.StringReader(val.toString());
             stmt.setCharacterStream(rows + 1, long_var, 16384);
             // long_var.close();
           } else if (vt.getType(paramNames[rows]) != java.sql.Types.LONGVARBINARY) {
             java.io.File os_file = new java.io.File(val.toString());
             if (os_file.exists() && os_file.isFile() && os_file.canRead()) {
               try {
                 java.io.FileInputStream long_var = new java.io.FileInputStream(os_file);
                 stmt.setBinaryStream(rows + 1, long_var, 16384);
                 // long_var.close();
               } catch (java.io.IOException ioe) {
               }
             } else stmt.setNull(rows + 1, 1);
           }
         }
         stmt.registerOutParameter(rows + 1, vt.getType(paramNames[rows]));
       }
     }
   }
 }