tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Propes, Barry L " <barry.l.pro...@citi.com>
Subject RE: JNDI setup oracle 11 g
Date Thu, 10 Jan 2013 18:08:22 GMT
Tony,

I have a similar standalone Java app that hits Oracle 11g.

At your line with the DBURL, I have something much more concise.

Where you have
public static final String DBURL = "jdbc:oracle:thin:@(DESCRIPTION = (ADDRESS = (PROTOCOL
= TCP)(HOST = abc-def-scan.corp.xyz.com)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED)
(SERVICE_NAME = SAMPLE.WORLD) )  )";


I simply have:
 String dbURL = "jdbc:oracle:thin:@dbservername.1526:servicename";

I set the rest of that string in my tnsnames.ora file - not sure if you're unable to do this
or not. I'd think you'd do it there.

Could that be where the error is stemming from?

The rest of it looks correct to me.



-----Original Message-----
From: tsidhu [mailto:tsidhuus@yahoo.com]
Sent: Thursday, January 10, 2013 9:52 AM
To: users@tomcat.apache.org
Subject: JNDI setup oracle 11 g

Hello,

I am able to connect to my database from a stand alone java program, however the same connection
information throws an exception when used via JNDI.

My stand alone app:

import java.sql.* ;  // for standard JDBC programs

public class TestCon {
        public static final String DBDRIVER = "oracle.jdbc.OracleDriver" ;
        public static final String DBURL = "jdbc:oracle:thin:@(DESCRIPTION = (ADDRESS = (PROTOCOL
= TCP)(HOST = abc-def-scan.corp.xyz.com)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED)
(SERVICE_NAME = SAMPLE.WORLD) )  )";
        public static final String DBUSER = "user1" ;
        public static final String DBPASS = "pass1" ;
        /**
         * @param args
         */
        public static void main(String[] args) {

                Connection conn = null ;    // DB CONNECTIONS
                PreparedStatement pstmt = null ;//  DB  OPERATIONS
                ResultSet rs = null ;       //  save the query result

                try {
                        Class.forName(DBDRIVER) ;

                        conn = DriverManager.getConnection(DBURL,DBUSER,DBPASS) ;
                        String sql = "select abc from xyz" ;   //sample query
                        Statement stmt = conn.createStatement() ;   // execute the query and
save
the result
                        rs = stmt.executeQuery(sql);

                        rs.close();
                        stmt.close();
                        conn.close();

                } catch (ClassNotFoundException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                }   // Load the ORACLE DRIVER
                catch(SQLException sql)
                 {
                        // TODO Auto-generated catch block
                        sql.printStackTrace();
                }
        }
}

MY JNDI / Context.xml configuration

<Resource name="jdbc/myoracle" auth="Container"
      type="javax.sql.DataSource"
                description="Oracle Datasource"
                driverClassName="oracle.jdbc.OracleDriver"

url="jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=abc-def-scan.corp.xyz.com)(PORT=1521))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=SAMPLE.WORLD)))"
username="user1" password="pass1" maxActive="20" maxIdle="10" maxWait="-1"
                validationQuery = "SELECT 1 FROM DUAL" />

The error I get when trying to run the following code from a servlet:

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

                        conn.close();
                        conn = null;
                }

ERROR

Jan 10, 2013 10:47:25 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 1249 ms
java.sql.SQLSyntaxErrorException: ORA-00911: invalid character

        at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:445)
        at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:396)
        at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:879)
        at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:450)
        at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:192)
        at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:531)
        at oracle.jdbc.driver.T4CStatement.doOall8(T4CStatement.java:193)
        at
oracle.jdbc.driver.T4CStatement.executeForDescribe(T4CStatement.java:
873)
        at
oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStateme
nt.java:1167)
        at
oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStateme
nt.java:1289)
        at
oracle.jdbc.driver.OracleStatement.executeInternal(OracleStatement.ja
va:1909)
        at
oracle.jdbc.driver.OracleStatement.execute(OracleStatement.java:1871)

        at
oracle.jdbc.driver.OracleStatementWrapper.execute(OracleStatementWrap
per.java:318)
        at
org.apache.tomcat.dbcp.dbcp.DelegatingStatement.execute(DelegatingSta
tement.java:264)
        at
org.apache.tomcat.dbcp.dbcp.DelegatingStatement.execute(DelegatingSta
tement.java:264)
        at
com.xyz.collections.controller.TestConnection.doGet(TestConnection.ja
va:43)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
        at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:305)
        at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:210)
        at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
alve.java:222)


The query runs fine when used in a stand alone java app, and I have tried all things in the
Context.XML to resolve.
I know it connects fine to the DB, however the getConnection from the JNDI datasource is causing
that error to be thrown.

Tony





--
View this message in context: http://tomcat.10.n6.nabble.com/JNDI-setup-oracle-11-g-tp4992221.html
Sent from the Tomcat - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message