aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes File IO in Stateless Session bean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "File IO in Stateless Session bean" Watch "File IO in Stateless Session bean" New topic
Author

File IO in Stateless Session bean

Seetesh Hindlekar
Ranch Hand

Joined: Feb 13, 2004
Posts: 244
Hi all,

Requirement : Read contents of a text file and upload the same to Oracle database (table).

I have created a Java class (application kind of) which opens, reads a file and transfers its data to a Oracle table.

Can I instantiate the same class within a Session Bean to perform the same operation or as per the EJB Restrictions this is not supposed to be done?

EJB Specifications 2.1 pdf guide
(refer 25.1.2 Programming restrictions
An enterprise bean must not use the java.io package to attempt to access files and directories in the file system. The file system APIs are not well-suited for business components to access data. Business components should use a resource manager API, such as JDBC, to store data.
)

Awaiting ur responses at the earliest.

Thanking in advance,

Seetesh
Aboo Bolaky
Greenhorn

Joined: Apr 02, 2004
Posts: 19
hi ya...
yeah ure right...the EJB specs specifically says that EJBS cannot perform file i/o. if u need to log messages or access files, you must find another mechanism...


Regards,<br />Aboo
Rajan Punchouty
Greenhorn

Joined: Mar 15, 2004
Posts: 21
Just a quick follow up.... rather a doubt...
How does Log4J work with EJB's then???
Aboo Bolaky
Greenhorn

Joined: Apr 02, 2004
Posts: 19
The other mechanism as Rajan pointed out is Log4J..
have a look at Vikram Goyal's introductory explanation
Seetesh Hindlekar
Ranch Hand

Joined: Feb 13, 2004
Posts: 244
Hi Aboo and Rajan,

Thks for ur post. I am using Log4J but my query was that I want to read a file (txt file) and insert its contents in a oracle table.

I have one file called FileIO.class which does the same. Question is If I instantiate this class in a business method of Stateless Session Bean and call the appropriate method of uploading the file contents in a oracle table, will it create any issues?

I am not bothered abt transaction issues here.

Rgds,

Seetesh
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
you can have a util class. which could has a method which reads the file and returns a string. just call that method from your bean, pass the filename and get the string.

how it sounds?
Seetesh Hindlekar
Ranch Hand

Joined: Feb 13, 2004
Posts: 244
Just trying the same. Will revert back shortly.

Seetesh
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: File IO in Stateless Session bean