No consigo realizar la conexión a una BD Oracle 10, instalada en el mismo ordenador después de crear un DataSource desde el Server Administration:
Código:
Después he añadido lo siguiente al "web.xml" (al que está en "conf/web.xml"):JNDI Name: jdbc/mioracle Data Source URL: jdbc:oracle:thin:@127.0.0.1:1521:exped JDBC Driver Class: oracle.jdbc.OracleDriver User Name: xxx Password: xxx Max. Active Connections: 4 Max. Idle Connections: 2 Max. Wait for Connection: 5000
Código:
Variables de entorno:<resource-ref> <description>Ejemlo Oracle DB</description> <res-ref-name>jdbc/mioracle</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> </resource-ref>
Código:
"In order to use OCI driver, you should have an Oracle client installed. You should have installed Oracle8i(8.1.7) client from cd, and download the suitable JDBC/OCI driver(Oracle8i 8.1.7.1 JDBC/OCI Driver)" LD_LIBRARY_PATH=/home/javier/oracle/lib ORACLE_BASE=/home/javier/oracle ORACLE_HOME=/home/javier/oracle ORACLE_LIBRARY_PATH=/home/javier/oracle/lib ORACLE_PATH=/home/javier/oracle/bin:/opt/bin ORACLE_SID=exped
--> tengo el fichero "ojdbc14.jar" en "common/lib"
"After renaming classes12.zip file to classes12.jar for Tomcat, copy it into $CATALINA_HOME/common/lib. You may also have to remove the javax.sql.* classes from this file depending upon the version of Tomcat and JDK you are using"
--> tengo "classes12.jar" en "common/lib", y parece que no es necesario quitar las clases del fichero, puesto que es para las versiones 4.0 y tengo la 4.1 según he leido en otro lado.
"Ensure that you have the ocijdbc8.dll or .so in your $PATH or LD_LIBRARY_PATH (possibly in $ORAHOME\bin) and also confirm that the native library can be loaded by a simple test program using System.loadLibrary("ocijdbc8");"
--> no encuentro ningún fichero .jar en el directorio de Oracle, que comience por "oci".
Código:
... Y el error me viene a dar en la última línea. Haciendo un System.out de "ds" me arroja: "org.apache.commons.dbcp.BasicDataSource@1295f e8". Un "printStackTrace()" arroja:Context initContext = new InitialContext(); Context envContext = (Context)initContext.lookup("java:comp/env"); DataSource ds = (DataSource)envContext.lookup("jdbc/mioracle"); Connection conn = ds.getConnection();
Código:
Por último, tengo también un ejemplo con "DriverManager" que funciona perfectamente:org.apache.commons.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null', cause: java.sql.SQLException: No suitable driver at java.sql.DriverManager.getDriver(DriverManager.java:243) at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:743) at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:518) at com.mhpsc.bdOracle.bdOracleDataSource.conectar(bdOracleDataSource.java:45) at org.apache.jsp.bd2_jsp._jspService(bd2_jsp.java:44) at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:92) at javax.servlet.http.HttpServlet.service(HttpServlet.java:809) at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:162) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:240) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:187) at javax.servlet.http.HttpServlet.service(HttpServlet.java:809) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:200) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:146) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:209) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:144) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948) at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2358) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:133) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596) at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:118) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:594) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:116) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:594) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:127) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948) at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:152) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705) at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577) at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683) at java.lang.Thread.run(Thread.java:595)
Código:
... llevo un par de días con esto y uffff public boolean conectar( String cadenaConexion, String usuario, String password ) { boolean ok = true; try { // Cargar el controlador JDBC Class.forName("oracle.jdbc.driver.OracleDriver").newInstance(); // Crear la conexión this.conexion = DriverManager.getConnection("jdbc:oracle:thin:" + usuario + "/" + password + "@" + cadenaConexion ); } catch (Exception e) { ok = false; } return ok; }