6

In a web application I want to store all doc, jpeg, pdf files in postgreSQL database. I know it can also be done by storing it on file system and storing its path in db, but I am not looking for that solution. I want to know following things:

  1. What should be data type for a table.
  2. Does it maintain formatting of doc ?
  3. And how storing it in postgreSQL can be achieved using java, hibernate technology. IS it required to create nativeSQL query?

Any pointers for this issue will be helpful.

O. Jones
  • 103,626
  • 17
  • 118
  • 172
devcodecc
  • 121
  • 1
  • 2
  • 8

1 Answers1

10

You'll want to store the binary data as the bytea type. Here is an example using JDBC and Postgres bytea:

http://jdbc.postgresql.org/documentation/80/binary-data.html

This post about using bytea and Hibernate might be of some use: proper hibernate annotation for byte[]

Community
  • 1
  • 1
Cody Caughlan
  • 32,456
  • 5
  • 63
  • 68