Solved

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

Posted on 2004-09-03
4
280 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

There is a lot to be said for protecting yourself and your accounts with 2 factor authentication.  I found to my own chagrin, that there is a big downside as well.
Article by: Justin
In light of the WannaCry ransomware attack that affected millions of Windows machines, you might wonder if your Mac needs protecting. Yes, it does and here is how to do it.
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

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