Announcement Announcement Module
Collapse
No announcement yet.
MSSQL Stored Procedure and Blob Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • MSSQL Stored Procedure and Blob

    Hi,

    I am trying to insert a blob using stored procedure of mssql.

    The example at the spring docs uses jdbc templates and as I search the forums, some only uses Oracle. JDBCTemplate is not an option.

    Code:
    public class FileAttachMentDao extends SimpleJdbcDaoSupport {
    
    	public int addFileAttachment(FileAttachment file) {
    		// TODO Auto-generated method stub
    		AddPMItemPerEquipment addEqptDetails = new AddPMItemPerEquipment(this
    				.getDataSource());
    
    		Map<String, Object> mapInputs = new HashMap<String, Object>();
    		mapInputs.put("Subject", file.getStrFileName());
    		mapInputs.put("Body", file.getContent());
    
    		Map result = addEqptDetails.execute(mapInputs);
    
    		int intResult = (Integer) result.get(DaoUtilConstants.RETURN_COUNT);
    
    		return intResult;
    	}
    
    	// Stored Proc call starts here
    	private class AddPMItemPerEquipment extends StoredProcedure {
    		public AddPMItemPerEquipment(DataSource ds) {
    			super(ds, "spAddAttachment");
    			declareParameter(new SqlParameter("Subject", Types.VARCHAR));
    			declareParameter(new SqlParameter("Body", Types.BLOB));
    			declareParameter(new SqlReturnUpdateCount(
    					DaoUtilConstants.RETURN_COUNT));
    			compile();
    		}
    	}
    
    }
    My SP is like this.

    Code:
    CREATE PROCEDURE spAddAttachment
    (
    	@Subject VARCHAR(256) = NULL,
    	@Body VARBINARY(MAX) = NULL
    )
    AS
    BEGIN
    	INSERT INTO [dbRTS].[dbo].[Image]
               ([Subject]
               ,[Body])
         VALUES
               (@Subject
               ,@Body
               )
    END
    GO
    My file attachment class goes like these
    Code:
    public class FileAttachment {
    	private String strFileName;
    	private InputStream content;
    	private Integer length;
    //getters and setters
    }
    Hope somebody could guide me as I am very much confused.
Working...
X