Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7971163
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:34:24+00:00 2026-06-04T07:34:24+00:00

This is my jboss/deploy/postgres-ds.xml file. The connection url, username and password is given here.

  • 0

This is my jboss/deploy/postgres-ds.xml file. The connection url, username and password is given here. How do I obtain a connection to this database in my servlet.

<local-tx-datasource>
        <jndi-name>PostgresDS</jndi-name>
        <connection-url>jdbc:postgresql://localhost:5432/postgres</connection-url>
        <driver-class>org.postgresql.Driver</driver-class>
        <user-name>postgres</user-name>
        <password>qwerty</password>
            <!-- sql to call when connection is created
            <new-connection-sql>some arbitrary sql</new-connection-sql>
            -->

            <!-- sql to call on an existing pooled connection when it is obtained from pool 
            <check-valid-connection-sql>some arbitrary sql</check-valid-connection-sql>
            -->

          <!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml (optional) -->

      </local-tx-datasource>

Should I obtain the connection like this in every servlet :

Connection conn =null; // Create connection object
        String database = "postgres"; // Name of database
        String user = "postgres"; //
             String password = "qwerty";
             String url = "jdbc:postgresql://localhost:5432/" + database;
ResultSet rs = null;
             ResultSetMetaData rsm = null;  
 try{
Class.forName("org.postgresql.Driver").newInstance();
//.newInstance()
} catch(Exception e) 
   {
System.err.println(e);
}

try{
conn = DriverManager.getConnection(url, user, password);

}catch(SQLException se) 
{
System.err.println(se);
}

If this has to be done everytime, then why give the url, username and password in the postgres-ds.xml file?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T07:34:25+00:00Added an answer on June 4, 2026 at 7:34 am

    you can use DataSource to get Connection like

    javax.naming.Context ic = new javax.naming.InitialContext();
    javax.naming.Context ctx = (javax.naming.Context) ic.lookup("java:");
    javax.sql.DataSource ds = (javax.sql.DataSource) ctx.lookup("PostgresDS");
    java.sql.Connection con = ds.getConnection();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

On JBoss 5.0.1 I have configured the deploy/properties-service.xml to reference a properties file like
I know how I'd do this using JBoss: create a *-ds.xml file, and drop
This is a continuation of the question here: JBoss - does app have to
I just added this to my web.xml on my JBOSS server. But it had
I am trying to deploy an ear file to JBOSS AS (defalut server). The
What is the correct way to turn off the JBoss hot deploy service? This
I deploy the rar file by placing it in the deployment folder in jboss
At present we deploy to JBoss 4.2 as this is the application server deployed
In JBoss 5.1.0, there is a file called <INSTANCE>/conf/bindingservice.beans/META-INF/bindings-jboss-beans.xml which includes some settings for
in JBoss 7.1, the default deploy directory is standalone/deployment. I want to change this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.