Link to home
Start Free TrialLog in
Avatar of hgbdelphi
hgbdelphi

asked on

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

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!
Avatar of sompol_kiatkamolchai
sompol_kiatkamolchai
Flag of Thailand image

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.
Avatar of hgbdelphi
hgbdelphi

ASKER

and anything....,rapaid?efficiency?

thanks!
ASKER CERTIFIED SOLUTION
Avatar of sompol_kiatkamolchai
sompol_kiatkamolchai
Flag of Thailand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thanks,i will create  connection pool.

Regard!