users@glassfish.java.net

Re: where to place JDBC driver's dot jar file in GlassFish directory structure?

From: <modjklist_at_comcast.net>
Date: Sun, 26 Feb 2012 23:00:09 +0000 (UTC)

After reading the GlassFish documentation, I have an idea how to create an JDBC Connection Pool and JDBC Resource. Let me try to narrow down my earlier question...

My original (e.g. relying on Linux java environment variables rather than GlassFish JDBC Connection Pool and JDBC Resource) java file starts out:

    import java.sql.*;
    import oracle.jdbc.*;
    import oracle.jdbc.pool.OracleDataSource;

    class JDBCexample {

        public static void main(String args[]) throws SQLException {
                Connection conn;
                Statement stmt;
                ResultSet rset;
                String query;
                String sqlString;
        
                String person_firstName;
                String person_lastName;
                String person_email;
                int person_salary;

                // connect to database
                OracleDataSource ds = new OracleDataSource();
                ds.setURL("jdbc:oracle:thin:myID/myPWD_at_192.168.0.1:1521:mySID");
                conn = ds.getConnection();

                // read something in database
                stmt = conn.createStatement();
                query = "SELECT first_name, last_name, email, salary FROM HR.Employees where rownum < 6";
                rset = stmt.executeQuery(query);
                while (rset.next()) {
                        person_firstName = rset.getString("first_name");
                        person_lastName = rset.getString("last_name");
                        person_email = rset.getString("email");
                        person_salary = rset.getInt("salary");
                        System.out.format(person_firstName + " " + person_lastName + " " + person_email + " %d%n", person_salary)
                }
    and so on...

QUESTION: How would I change the above code after I create a JDBC Connection Pool (named: myPool) and a JDBC Resource (named: myDBPool)? If it matters, I'm using Oracle 11.2, CentOS 6.2, GlassFish 3.1.1 with mod_jk and fronted by Apache 2.2 webserver, JDK 1.6. I don't have any clustering or load-balancing. Thanks in advance.


----- Original Message -----
From: modjklist_at_comcast.net
To: users_at_glassfish.java.net
Sent: Sunday, February 26, 2012 10:01:30 AM
Subject: where to place JDBC driver's dot jar file in GlassFish directory structure?

Hello, I'm running an Linux (CentOS 6.2) application that reports the following error when trying to establish a connection to an Oracle database:

java.lang.NoClassDefFoundError: oracle/jdbc/pool/OracleDataSource

I've verified the CLASSPATH environment is set correctly to access the driver file: ojdbc6_g.jar

QUESTION 1: It seems GlassFish isn't using this environment variable(?). Can I just drop the driver's jar file into a specific directory?

Is the following directory the right one?

domain-dir/lib/applibs

QUESTION 2: Can I just drop it in using Linux command line arguments (e.g. "cp /path/to/file/filename /path/to/destination/directory"), or do I need to issue something specific within GlassFish's asadmin command prompt?

I assume restarting the domain would be required.

Any advice appreciated.