I'm trying to run a java web application on myEclipse by deploying it on Tomcat v7.0. I'm trying to connect it to my Oracle database 19c. I've added the ojdbc jar file in the classpath like shown here. Yet I'm still getting the error.
And the root cause of the error is shown to be like this
Below is my context.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<Context>
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<Resource name="jdbc/secure_mail" auth="Container" type="javax.sql.DataSource"
driverClassName="oracle.jdbc.OracleDriver" url="jdbc:oracle:thin:@localhost:1521:orcl"
username="c##scott" password="mathsformula" maxActive="20" maxIdle="10"
maxWait="-1" />
</Context>
And this is my datasource definition:
public void init(ServletConfig config) throws ServletException {
try {
InitialContext initContext = new InitialContext();
Context env = (Context) initContext.lookup("java:/comp/env");
ds = (DataSource) env.lookup("jdbc/secure_mail");
} catch (NamingException e) {
throw new ServletException();
}
}
Any idea what could be causing this? Am I adding the wrong JAR file, or is it because I'm using Tomcat v7.0? Thanks.
Edit:
I'm also getting this error message displayed at the beginning of the console whenever I run the web application:
java.lang.UnsatisfiedLinkError: C:\Users\kuman\Downloads\apache-tomcat-7.0.109-src\apache-tomcat-7.0.109-src\apache-tomcat-7.0.47\bin\tcnative-1.dll: Can't load IA 32-bit .dll on a AMD 64-bit platform
at java.base/java.lang.ClassLoader$NativeLibrary.load0(Native Method)
at java.base/java.lang.ClassLoader$NativeLibrary.load(ClassLoader.java:2452)
at java.base/java.lang.ClassLoader$NativeLibrary.loadLibrary(ClassLoader.java:2508)
at java.base/java.lang.ClassLoader.loadLibrary0(ClassLoader.java:2704)
at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2669)
at java.base/java.lang.Runtime.loadLibrary0(Runtime.java:807)
at java.base/java.lang.System.loadLibrary(System.java:1907)
at org.apache.tomcat.jni.Library.<init>(Library.java:42)
at org.apache.tomcat.jni.Library.initialize(Library.java:174)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at org.apache.catalina.core.AprLifecycleListener.init(AprLifecycleListener.java:180)
at org.apache.catalina.core.AprLifecycleListener.isAprAvailable(AprLifecycleListener.java:85)
at org.apache.catalina.connector.Connector.setProtocol(Connector.java:595)
at org.apache.catalina.connector.Connector.<init>(Connector.java:69)
at org.apache.catalina.startup.ConnectorCreateRule.begin(ConnectorCreateRule.java:62)
at org.apache.tomcat.util.digester.Digester.startElement(Digester.java:1276)
at java.xml/com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:518)
at java.xml/com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocumentParser.emptyElement(AbstractXMLDocumentParser.java:183)
at java.xml/com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(XMLDocumentFragmentScannerImpl.java:1386)
at java.xml/com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2725)
at java.xml/com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:605)
at java.xml/com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:541)
at java.xml/com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:888)
at java.xml/com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:824)
at java.xml/com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
at java.xml/com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1224)
at java.xml/com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:635)
at org.apache.tomcat.util.digester.Digester.parse(Digester.java:1537)
at org.apache.catalina.startup.Catalina.load(Catalina.java:617)
at org.apache.catalina.startup.Catalina.load(Catalina.java:665)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at org.apache.catalina.startup.Bootstrap.load(Bootstrap.java:281)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:455)
Jun 19, 2021 12:12:40 PM org.apache.catalina.core.AprLifecycleListener init
You should put the jar in the CATALINA_HOME/lib directory, i.e. the lib folder of you tomcat installation dir.