尽管添加了 JAR 文件,但无法加载 JDBC 驱动程序 class 'oracle.jdbc.OracleDriver'
Cannot load JDBC driver class 'oracle.jdbc.OracleDriver' despite adding JAR file
我试图通过在 Tomcat v7.0 上部署它来 运行 myEclipse 上的 java Web 应用程序。我正在尝试将它连接到我的 Oracle 数据库 19c。我已经在类路径中添加了 ojdbc jar 文件,如图所示 here。
但我仍然收到错误。
错误的根本原因显示为 this
下面是我的 context.xml 文件:
<?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>
这是我的数据源定义:
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();
}
}
知道是什么原因造成的吗?我添加了错误的 JAR 文件,还是因为我使用的是 Tomcat v7.0?谢谢。
编辑:
每当我 运行 Web 应用程序时,控制台开头也会显示此错误消息:
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
你应该把jar放在CATALINA_HOME/lib目录下,即你tomcat安装目录的lib文件夹。
我试图通过在 Tomcat v7.0 上部署它来 运行 myEclipse 上的 java Web 应用程序。我正在尝试将它连接到我的 Oracle 数据库 19c。我已经在类路径中添加了 ojdbc jar 文件,如图所示 here。 但我仍然收到错误。
错误的根本原因显示为 this
下面是我的 context.xml 文件:
<?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>
这是我的数据源定义:
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();
}
}
知道是什么原因造成的吗?我添加了错误的 JAR 文件,还是因为我使用的是 Tomcat v7.0?谢谢。
编辑:
每当我 运行 Web 应用程序时,控制台开头也会显示此错误消息:
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
你应该把jar放在CATALINA_HOME/lib目录下,即你tomcat安装目录的lib文件夹。