GeeCON Prague 2014*
The moose likes JDBC and the fly likes How to connect a database from Servlet/Jsp, EJB Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Databases » JDBC
Bookmark "How to connect a database from Servlet/Jsp, EJB" Watch "How to connect a database from Servlet/Jsp, EJB" New topic
Author

How to connect a database from Servlet/Jsp, EJB

AMAL KANTI SEAL
Greenhorn

Joined: Jan 31, 2005
Posts: 6
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).
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

http://java.sun.com/docs/books/tutorial/jdbc/index.html


Groovy
Kai Witte
Ranch Hand

Joined: Jul 17, 2004
Posts: 356
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


Kai Witte's business website Kai Witte's private homepage
 
GeeCON Prague 2014
 
subject: How to connect a database from Servlet/Jsp, EJB