Win a copy of JDBC Workbook this week in the JDBC and Relational Databases forum
or A Day in Code in the A Day in Code 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 ...
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • salvin francis
  • fred rosenberger

Database Access

Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it possible to make a direct database connection from inside a CM bean? I have a bean that registers customers
and stores their details in a database (Oracle 9i). The bean handles all the database access. I now want to enhance
this bean and encrypt the credit card numbers using 3des and a key stored in the database. Can I open a connection
to the database from inside the bean to access the key which is stored in a different table or is this not possible
because of the container managed persistence? If so does anyone have any suggestions on how I could achieve this,
I'm new to EJBs and have run out of ideas. Any help is greatly appreciated. Thanks.
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should not make connections to the database from a CMP. You can make connections from inside a Session Bean for example, by looking up the datasource from the app server and then getting a connection from that datasource.
If you want to change some data from inside a CMP into another table than the one the bean is responsible for, you should have an entity bean for the second table and make this responsible for the changes.
For your example you should have two entity beans: CustomerBean and KeyBean.
When registering the customer using the CustomerBean, when you need to encrypt the credit card numbers you call the KeyBean for finding out the key for 3des. You calculate the encrypted key using KeyBean and then you store it using CustomerBean.
[ February 17, 2004: Message edited by: sergiu truta ]
Looky! I'm being abducted by space aliens! Me and this tiny ad!
Devious Experiments for a Truly Passive Greenhouse!
    Bookmark Topic Watch Topic
  • New Topic