Solved

can experts tell me different about container datasource and jdbc connection?

Posted on 2004-09-03
4
267 Views
Last Modified: 2010-04-01
hi,experts,
  i don't know about define connection in jboss datasource and define connection in my class will some different,can tell me?
  in jboss,i define connection in *.xml,like this

<datasources>
  <local-tx-datasource>
    <jndi-name>MSSQLDS</jndi-name>
    <connection-url>jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=CommunityMedical</connection-url>
    <driver-class>com.microsoft.jdbc.sqlserver.SQLServerDriver</driver-class>
    <user-name>sa</user-name>
    <password>btn</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>
        -->

  </local-tx-datasource>

</datasources>
 and i will call like this in jsp:

     Context ctx = new InitialContext();
     ds = (javax.sql.DataSource)ctx.lookup("java:/MSSQLDS");
     Connection conn=ds.getConnection();
     Statement dbConn=conn.createStatement();

and i define my connection in myclass,like this

      public DBConn() {
            String sqlDriver = ConfigFile.SQL_Driver;
            String sqlJdbc = ConfigFile.SQL_JDBC;
            String sqlUser = ConfigFile.SQL_USER;
            String sqlPwd = ConfigFile.SQL_PWD;
            try {
                  Class.forName(sqlDriver);
                  conn = DriverManager.getConnection(sqlJdbc, sqlUser, sqlPwd);
                  stmtScroll = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
                  stmt = conn.createStatement();
            } catch (Exception e) {
                  e.printStackTrace();
            }
      }


i don't know two type get connection will some different, efficiency?standard?or ....

thanks!
0
Comment
Question by:hgbdelphi
  • 2
  • 2
4 Comments
 
LVL 11

Expert Comment

by:sompol_kiatkamolchai
ID: 11978961
To define datasource in JBoss, it will help us easier to manage connection than you hard-code in java class.
If you want to change something like username/password to access database, no need to recompile source code and have a central of management resource.
0
 

Author Comment

by:hgbdelphi
ID: 11979113
and anything....,rapaid?efficiency?

thanks!
0
 
LVL 11

Accepted Solution

by:
sompol_kiatkamolchai earned 50 total points
ID: 11983060
For efficiency point of view,

If you define in JBoss, It will pre-open connection before using, that means when you want to use connection, there is no need to re-open connection again. you can get it from JNDI. I think you can also set datasource to point to connection pool as well.
0
 

Author Comment

by:hgbdelphi
ID: 11986503
thanks,i will create  connection pool.

Regard!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
build fail in maven project 11 170
own marker interface 1 44
struts exact match support 3 45
maven webservice example issue 2 89
Never store passwords in plain text or just their hash: it seems a no-brainier, but there are still plenty of people doing that. I present the why and how on this subject, offering my own real life solution that you can implement right away, bringin…
In  today’s increasingly digital world, managed service providers (MSPs) fight for their customers’ attention, looking for ways to make them stay and purchase more services. One way to encourage that behavior is to develop a dependable brand of prod…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now