1 Reply Latest reply on May 12, 2004 7:32 AM by darranl

    CMP/JCA Database connections

    cparsons

      I am not even sure if I am referring to the correct terms, but having managed to successfully connect to data by passing the id and password for the database via code, I am now trying to set up this information in the JBoss environment so that I can use connection pooling, and not have the password for the database in my code?

      I have some sample code below, my question is what do I have to do to be able to use the 'MyDS' datasource??

      // Step 1. Look up the DataSource
      InitialContext ic = new InitialContext();
      DataSource ds = (DataSource) ic.lookup("jdbc/MyDS");

      // Step 2. Get a connection from the pool
      Connection conn = ds.getConnection();

      // Step 3. Execute query
      Statement stmt = conn.createStatement();
      stmt.execute("SELECT * FROM USERID.EMPLOYEE");

      // Step 4. Get the results
      ResultSet rs = stmt.getResultSet();
      while (rs.next()) {
      String firstCol = rs.getString(1);
      int secondCol = rs.getInt(2);
      ...
      }

      // Step 5. Return connection to the pool
      conn.close();

      I think this means adding something to the 'standardjbosscmp-jdbc.xml' file? I cannot find a _simple_ example I can look at to get me started, any pointers would be greatly appreciated!

      Thanks

      Chris Parsons