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 ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

How to connect a database from Servlet/Jsp, EJB

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please tell me giving concrete example code how I can connect to a database ( say SQL Server or MS Access) and interact with it {store/retrieve data).
 
Ranch Hand
Posts: 356
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello,

the only thing you have to know additionally to what is said in that tutorial is how to configure and declare a DataSource. This is done using the <resource-ref> tag in the deployment descriptor, for example:

In your program you can then look it up using JNDI. Note that res-ref-name is relative to java:comp/env.

The rest of the configuration depends on the web container or application server.

Note that it is common to use a more abstract persistence API rather than using JNDI directly. Common choices are BMP, Hibernate or a custom DAO implementation.

Kai
 
What kind of corn soldier are you? And don't say "kernel" - that's only for this tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic