My J2EE application has to access data stored in a database and also some binary data which is usually stored as files (it can be several MBs).
How can I do that using EJB? , because it is not allowed to do any file IO in EJB.
Is it possible to store the files in the database as binary data, or it is not advisable to do so?
-
How to store binary data using EJB? (3 messages)
- Posted by: frank montoya
- Posted on: May 09 2004 12:12 EDT
Threaded Messages (3)
- How to store binary data using EJB? by ketan padia on May 09 2004 21:12 EDT
- How to store binary data using EJB? by ketan padia on May 09 2004 21:17 EDT
- How to store binary data using EJB? by Vladimir Chizhov on May 18 2004 03:52 EDT
-
How to store binary data using EJB?[ Go to top ]
- Posted by: ketan padia
- Posted on: May 09 2004 21:12 EDT
- in response to frank montoya
try this mate.....i'm not pretty sure but it should work
byte[] jpgimage;
< write code to convert the image file to bytes >
/* try inserting the image in DB */
try {
/* make sure u put question mark where u want to insert ur image data */
PreparedStatement prep = con.prepareStatement("INSERT INTO tablename VALUES ( "x","y", ?)");
/* 3 is the index of the values need to insert */
prep.setBytes( 3, jpgimage);
prep.executeUpdate();
prep.close();
con.close();
}
catch ( SQLException sqlE ) {
System.err.println("Couldn`t insert image!");
return;
} -
How to store binary data using EJB?[ Go to top ]
- Posted by: ketan padia
- Posted on: May 09 2004 21:17 EDT
- in response to frank montoya
storing images to database is not advisable if the number of images are in large -
How to store binary data using EJB?[ Go to top ]
- Posted by: Vladimir Chizhov
- Posted on: May 18 2004 03:52 EDT
- in response to frank montoya
because it is not allowed to do any file IO in EJB
Why not? Just set up your application server this way:
grant codebase "..." {
permission java.io.FilePermission "<};
I think it's a solution too.