IllegalStateException:无法加载JDBC驱动,添加ojdbc14.jar仍报错求助
Hey there, let's work through this frustrating JDBC driver issue together. You mentioned you added ojdbc14.jar to src/main/resources/lib but still hit the error—here are the most common fixes to get this sorted:
Don't rely on
src/main/resources/libfor dependencies
That directory is meant for resource files (like properties, XML configs), not JAR dependencies. Build tools like Maven/Gradle won't automatically include JARs here in your project's classpath. Instead:- If using Maven, install the JAR to your local repository first with this command (replace the file path with your actual
ojdbc14.jarlocation):
Then add this dependency to yourmvn install:install-file -Dfile=/path/to/ojdbc14.jar -DgroupId=com.oracle -DartifactId=ojdbc14 -Dversion=10.2.0.4.0 -Dpackaging=jarpom.xml:<dependency> <groupId>com.oracle</groupId> <artifactId>ojdbc14</artifactId> <version>10.2.0.4.0</version> </dependency> - If you're not using a build tool, manually add the JAR to your IDE's classpath:
- In IntelliJ: Right-click the
ojdbc14.jar→ Add as Library - In Eclipse: Right-click your project → Build Path → Add External Archives
- In IntelliJ: Right-click the
- If using Maven, install the JAR to your local repository first with this command (replace the file path with your actual
Double-check your driver class name
Whileoracle.jdbc.driver.OracleDriveris valid for ojdbc14, make sure there are no typos (case sensitivity matters!). For reference, newer Oracle drivers useoracle.jdbc.OracleDriver, but the older one should still work here.Verify the JAR file is intact
Sometimes downloaded JARs get corrupted. Try re-downloading a fresh copy ofojdbc14.jarfrom a trusted source and replace the existing one in your project.Check your Spring config for typos
Ensure your Spring bean configuration (XML or annotation-based) has the correctdriverClassNameproperty. For example, in XML:<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" /> <!-- other properties like url, username, password --> </bean>Make sure there are no extra spaces or incorrect spelling in the value.
内容的提问来源于stack exchange,提问作者Soham Banerjee

