on 09-29-2006 12:34 PM
Hi,
I want to access database from a servlet.
Can somebody please guide me to a helpful link!
Thanks,
Gagan.
Hi Mukesh,
Thanks for your quick reply.
I checked out the links. But that is not exactly what I am looking for.
I wanted to connect to the DB by looking up the Database <b>Alias</b>. This method involved writing <b>resource references</b> in web.xml. I am not sure exactly how to do it.
It'll be really nice if someone can guide me as to how to go about the connection using this approach.
Thanks,
Gagan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Mukesh,
Now we are getting closer. This is preciously how I want to access the database.
But there was one problem.
The links show how to do it, but none of them give examples of coded web.xml's or web-j2ee-engine.xml's.
I cannot do it using the IDE now, as I don't think the latest versions provide the tabs that are needed to create the resource-ref's for a servlet.
So, now I think, you'll get my problem.
Thanks,
Gagan
Hi,
in web.xml add the following reference, where the res-ref-name is the alias described in data-source-aliases.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<resource-ref>
<res-ref-name>jdbc/TestDS</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
</web-app>
Hello Violeta,
Thanks. Problem solved.
(For others reference)
I added the data-source-aliases.xml
as:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE data-source-aliases SYSTEM "data-source-aliases.dtd">
<data-source-aliases>
<aliases>
<data-source-name>${com.sap.datasource.default}</data-source-name>
<alias>SAP/xyz</alias>
</aliases>
</data-source-aliases>
And the altered web.xml as Violeta mentioned.
Best Regards,
Gagan.
Hi
See this sample
http://java.sun.com/developer/onlineTraining/Programming/BasicJava1/dba.html
http://www.jguru.com/faq/view.jsp?EID=161
Kind Regards
Mukesh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
90 | |
10 | |
10 | |
10 | |
7 | |
7 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.