Win a copy of Learn Java with Math: Using Fun Projects and Games this week in the Beginning Java forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Junilu Lacar
  • Martin Vashko
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Scott Selikoff
  • salvin francis
  • Piet Souris

File IO in Stateless Session bean

 
Ranch Hand
Posts: 244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just a quick follow up.... rather a doubt...
How does Log4J work with EJB's then???
 
Aboo Bolaky
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The other mechanism as Rajan pointed out is Log4J..
have a look at Vikram Goyal's introductory explanation
 
Seetesh Hindlekar
Ranch Hand
Posts: 244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just trying the same. Will revert back shortly.

Seetesh
 
Make yourself as serene as a flower, as a tree. And on wednesdays, as serene as this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!