I'm happy to report that this newbie successfully set up a JNDI
Datasource <insert self-satisfied cheer here>.

I now have a question about the best way to create connections in my web
application.  Previously, I used this class in other beans in order to
create and access connections:

public class dbConnection {
    private static String url = "jdbc:oracle:thin:@server:1521:sid";
    private static String username = "scott";
    private static String password = "tiger";

    public boolean driverLoaded = false;

    public synchronized Connection getConnection() throws SQLException {
        Connection connection;

        if (!driverLoaded) {
            try {
 
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
                driverLoaded = true;
            } catch (ClassNotFoundException ex) {
                throw new SQLException("Can't find driver " +
ex.getMessage());
            } catch (Exception e) {
                System.out.println("Something else happened in
dbConnection: " + e.getMessage());
                e.printStackTrace();
            }
        }
        connection = DriverManager.getConnection(getUrl(),
getUsername(), getPassword());
        return connection;
    }


I'm planning using the same class, modified slightly, to serve up
connections from the Pool:

public class dbConnection {
    private static String url = "jdbc:oracle:thin:@server:1521:sid";
    private static String username = "scott";
    private static String password = "tiger";

    public boolean driverLoaded = false;

    public synchronized Connection getConnection() throws SQLException {
        Connection connection;

        Context initContext = new InitialContext();
          Context envContext  =
(Context)initContext.lookup("java:/comp/env");
          DataSource ds =
(DataSource)envContext.lookup("jdbc/myoracle");
          connection = ds.getConnection();

        return connection;
    }

Am I on the right track with this, or can I expect some grief?  I'm
using the Shale framework with JavaServer Faces.

Thanks for your time.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to