| Author |
Retrieving blob object from postgres database
|
Dipika Saxena
Greenhorn
Joined: Mar 27, 2006
Posts: 3
|
|
Hi all, I inserted a jsp file as a blob object in my postgres database. The column data type for storing blob object is bytea. I used the following code for inserting my jsp: public void insertRegistrationMailTemplate() { LobHandler lobHandler = new DefaultLobHandler(); InputStream stream = null; Object[] params = null; try { stream = new BufferedInputStream( new FileInputStream(AllConstants.MAIL_TEMPLATES_PATH+ "\\registrationMail.jsp") ); } catch(FileNotFoundException e) { e.printStackTrace();} try { params = new Object[]{ AllConstants.REGISTRATION_MAIL_TEMPLATE_NAME, new SqlLobValue(stream, stream.available(), lobHandler)}; } catch(IOException e) { e.printStackTrace(); } getJdbcTemplate().update( MailQueries.registrationMailTemplate, params, new int[] { Types.VARCHAR, Types.BLOB}); } It inserts the file without any error. Now I want to retrieve the contents of this file. I have written the following code: public String getMailTemplate(int template_id) { InputStream stream = null; Object[] params = new Object[]{ new Integer(template_id) }; stream = (InputStream) getJdbcTemplate().queryForObject( MailQueries.getTemplate,params,InputStream.class); } but it gives the following exception: org.springframework.dao.TypeMismatchDataAccessException: Result object with column type 'bytea' and value [[B@1bbbafc] is of type [[B] and could not be converted to required type [java.io.InputStream] What is the correct way to retrieve the contents of my jsp file from blob object of database? Thanks, Dipika
|
 |
 |
|
|
subject: Retrieving blob object from postgres database
|
|
|