Mysql
 sql >> Database >  >> RDS >> Mysql

Modo corretto per caricare file binari su MySQL tramite Spring MVC

Hai provato questo:

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);
        }

});