• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Retrieving blob object from postgres database

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic