cancel
Showing results for 
Search instead for 
Did you mean: 

Database access from a servlet?

Former Member
0 Kudos

Hi,

I want to access database from a servlet.

Can somebody please guide me to a helpful link!

Thanks,

Gagan.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

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>

Former Member
0 Kudos

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.

Answers (1)

Answers (1)

Former Member
0 Kudos