Solved

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

Posted on 2004-09-03
4
269 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
servlet concurrency 13 93
sortaSum challenge java 17 171
How to find missing packages when using Netbeans IDE 8.1 ? 19 46
JSONSerializer.toJSON in JSP generating error 8 65
In the hope of saving someone else's sanity... About a year ago we bought a Cisco 1921 router with two ADSL/VDSL EHWIC cards to load balance local network traffic over the two broadband lines we have, but we couldn't get the routing to work consi…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

864 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

23 Experts available now in Live!

Get 1:1 Help Now