sql >> Base de Datos >  >> RDS >> Mysql

Forma correcta de cargar un archivo binario a MySQL a través de Spring MVC

Has probado esto:

jdbcTemplate.execute("INSERT INTO File (name, type, data) VALUES (?, ?, ?)",
    new AbstractLobCreatingPreparedStatementCallback(lobHandler){
        @Override
        protected void setValues(PreparedStatement ps,
            LobCreator lobCreator) throws SQLException,
            DataAccessException {
            ps.setString(1, dFile.getName());
            ps.setString(2, dFile.getType());
            Blob blob = dFile.getData();
            int length = (int)blob.length();
            byte[] b = dFile.getData(); //blob.getBytes(1, length);
            int length = b.length;
            InputStream is=new ByteArrayInputStream(b);
            ps.setBinaryStream(3,  is, length);
        }

});