How to store binary data using EJB?

Discussions

EJB design: How to store binary data using EJB?

  1. How to store binary data using EJB? (3 messages)

    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?
  2. 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;
     }
  3. storing images to database is not advisable if the number of images are in large
  4. 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.