Spring JdbcTemplate - Insert blob and return generated key

后端 未结 11 1852
猫巷女王i
猫巷女王i 2020-12-15 06:06

From the Spring JDBC documentation, I know how to insert a blob using JdbcTemplate

final File blobIn = new File(\"spring2004.jpg\");
final InputStream blobIs         


        
11条回答
  •  清歌不尽
    2020-12-15 06:13

    Please use:

    addValue("p_file", noDataDmrDTO.getFile_data(), Types.BINARY)
    
    noDataDmrDTO.getFile_data() is byte array.
    
    
    {
     simpleJdbcCall =
              new SimpleJdbcCall(jdbcTemplate).withProcedureName("insert_uploaded_files").withCatalogName("wct_mydeq_stg_upld_pkg")
                  .withSchemaName("WCT_SCHEMA");
    
     SqlParameterSource sqlParms =
            new MapSqlParameterSource().addValue("p_upload_idno", Integer.parseInt("143"))
                .addValue("p_file_type_idno", Integer.parseInt(noDataDmrDTO.getFile_type_idno())).addValue("p_file_name", noDataDmrDTO.getFile_name())
                .addValue("p_file", noDataDmrDTO.getFile_data(), Types.BINARY).addValue("p_comments", noDataDmrDTO.getComments())
                .addValue("p_userid", noDataDmrDTO.getUserid());
    
    
        simpleJdbcCallResult = simpleJdbcCall.execute(sqlParms);
    
    }
    

提交回复
热议问题