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-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to