Subject: Connecting to oracle database in struts
Posted By: Manvi Post Date: 6/7/2006 11:37:18 AM
Hi,
I'm new to this forum. I'm having trouble in connecting my web application to the oracle database. Can anyone guide me on the steps i need to follow to do the same? Also, does connecting to the database have any connection with the server i'm using? I was earlier using the Tomcat server, but now i'm using JBoss application server. I would appreciate if someone can answer my query at the earliest. I'm in need of urgent help. Thanks in advance!
Manvi

Reply By: Lalit2512 Reply Date: 6/28/2006 2:14:25 PM
Hi manvi,
Please If u get answer let me know. Actualy i want to connect to oracle database and i have tomcat server. I am getting error. What jar file is needed?  How to connect? Its urgent can u send me steps to connect?

Reply By: panacea Reply Date: 7/12/2006 4:57:03 AM
I use oracle-jdbc-8.1.7.1.jar and Class.forName("oracle.jdbc.driver.OracleDriver").newInstance() for classloading.

Jon Emerson
http://blogs.adobe.com/jon.emerson/
Reply By: sachin.tathod Reply Date: 8/7/2006 10:53:20 PM
Hi ,u can use following code to get connection with oracle database



public Connection getDBConnection(String dataSourceName, String dbName)
        throws PasskeyException {
        java.sql.Connection connection = null;
        long timeNowiS = System.currentTimeMillis();

        try {
            logger.debug("Just entering getdbcon  get App Name "+timeNowiS);
            javax.sql.DataSource dataSource = null;

            if (dbContextlist.containsKey(dataSourceName)) {
                dataSource = (javax.sql.DataSource) dbContextlist.get(dataSourceName);
            } else {
                Context context = new InitialContext();
                dataSource = (javax.sql.DataSource) context.lookup(dataSourceName);
                dbContextlist.put(dataSourceName, dataSource);
                context.close();
            }
            //PerformanceTimer time1=new PerformanceTimer();
            String appName = PasskeyUtils.getAppName();
            logger.debug("getdbcon  get App Name "+appName);
            String username = PropertyFileReader.getPasskeyProperty(dbName +"."+appName+
            ".username");
          String password = PropertyFileReader.getPasskeyProperty(dbName + "."+appName+
          ".pwd");
            if ((password == null) || password.trim().equals("")) {
                throw new SQLException("no password --for db " + dbName+"user****"+username+"=="+appName);
            }

            connection = dataSource.getConnection(username, password);
            connection.setCatalog(dbName);
        } catch (java.sql.SQLException sqlEx) {
            throw new PasskeyException("in servicelocator.getDBConnection",
                sqlEx);
        } catch (Exception genericEx) {
            throw new PasskeyException("in servicelocator.getDBConnection",
                genericEx);
        }
        logger.debug("Just exiting  getdbcon  get App Name "+timeNowiS+" and now it is "+System.currentTimeMillis());
        return connection;
    }


Thanks and Regards,
SACHIN S.TATHOD
Patni Computer System Ltd.
Magarpatta City, Cyber City,
Tower 3,Level I & II,
Hadapsar,Pune - 411028
Mobile No:- +91-9881239401
Email ID:- sachin.tathod@patni.com

Go to topic 43113

Return to index page 209
Return to index page 208
Return to index page 207
Return to index page 206
Return to index page 205
Return to index page 204
Return to index page 203
Return to index page 202
Return to index page 201
Return to index page 200