?
Solved

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

Posted on 2004-09-03
4
Medium Priority
?
281 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 200 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

If you're a modern-day technology professional, you may be wondering if certifications are really necessary. They are. Here's why.
IF you are either unfamiliar with rootkits, or want to know more about them, read on ....
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses
Course of the Month8 days, 11 hours left to enroll

764 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