Wednesday, December 11, 2019

How To Gear Upwardly Java.Lang.Classnotfoundexception Oracle.Jdbc.Driver.Oracledriver [Solved]

Scenario : Your Java program, either standalone or Java spider web application is trying to connect to Oracle database using type iv JDBC sparse driver "oracle.jdbc.driver.oracledriver", JVM is non able to discovery this shape at runtime. This JAR comes inwards ojdbc6.jar or ojdbc6_g.jar which is most in all likelihood non available inwards classpath.

Cause : When you lot connect to Oracle database from Java program, your computer program loads the implementation of Driver interface provided past times the database vendor using class.forName() method, which throws ClassNotFoundException when driver shape is non flora inwards classpath. In illustration of Oracle the driver implementation is oracle.jdbc.driver.oracledriver and "java.lang.classnotfoundexception oracle.jdbc.driver.oracledriver" error betoken that this shape is  not available inwards classpath. Since this shape is bundled into ojdbc6.jar, its unremarkably the illustration of this JAR non acquaint inwards Classpath


As I said this mistake may come upwards fifty-fifty if you lot are connecting to Oracle database from spider web server similar Tomcat. This is the stack-trace from Tomcat, when my Java app was failed to charge this shape :

java.lang.ClassNotFoundException: oracle.jdbc.OracleDriver at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1680) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1526) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Unknown Source)

You tin run into that due to a telephone telephone to Class.forName(), WebappClassLoader tries to charge this shape file, it only looks at WEB-INF/lib directory, thus if this shape is non acquaint inwards whatever JAR file at that place thus it volition throw java.lang.classnotfoundexception oracle.jdbc.driver.oracledriver




How to solve  java.lang.ClassNotFoundException: oracle.jdbc.OracleDriver

Solution : If you lot already convey this JAR thus include this inwards your classpath, for illustration if you lot are running heart too mortal Java application using main() method thus only brand certain that you lot move a custom classpath specified past times -cp or -classpath parameter to coffee ascendance too place of this JAR there.

If you lot are connecting to oracle database using Java spider web application (Servlet, JSP) thus brand certain that this JAR is acquaint inwards WEB-INF/lib folder. If you lot are using tomcat to deploy your Java spider web application, You tin besides position this ojdbc.jar inwards apache-tomcat/lib directory, but scream upwards that thus it volition non hold upwards loaded past times WebAppClassLoader but its parent, which agency it volition hold upwards available to all spider web application too volition non hold upwards unloaded when you lot take your spider web application.

If you lot don't convey ojdbc6.jar or ojdbc_g.jar thus download them from /search?q=" target="_blank"> java.lang.classnotfoundexception oracle.jdbc.driver.oracledriver mistake inwards Java

 either standalone or Java spider web application is trying to connect to Oracle database using  How to Fix java.lang.classnotfoundexception oracle.jdbc.driver.oracledriver [Solved]


Where to download Oracle 11g too 10g JDBC driver JARs

Oracle driver, oracle.jdbc.driver.oracledriver is available inwards ojdbc6.jar too ojdbc_g.jar for Oracle 11g, but if you lot are connecting to Oracle 10g database too running on Java 1.4 or Java 1.5 thus you lot should either move ojdbc14.jar, or move classes12.jar if your Java application is running on JDK 1.2 too JDK 1.3. Though I propose to move debug JAR files e.g. ojdbc14_g.jar or classes12_g.jar because they are compiled using javac -g selection too comprise useful tracing information.

You tin download Oracle JDBC driver Jar files from http://www.oracle.com/technetwork/apps-tech/jdbc-10201-088211.html. ojdbc6.jar comprise classes for move alongside Java 1.6 version, thus if your application is running on Java half dozen too connecting to Oracle 11g database thus move ojdbc6 too ojdbc6_g.jar. If your computer program is running on Java five too connecting ot Oracle 11g thus move ojdbc5.jar or ojdbc5_g.jar. You tin download Oracle 11g JDBC drive JAR files from http://www.oracle.com/technetwork/apps-tech/jdbc-112010-090769.html.


Summary

  • If you lot are connecting to Oracle 11g from Java too running on version Java half dozen thus include ojdbc6.jar or ojdbc6_g.jar inwards your application's classpath.
  • If you lot are connecting to Oracle 11g from Java five thus include ojdbc5.jar or ojdbc5_g.jar in your application's classpath.
  • Difference betwixt ojdbc6.jar too ojdbc6_g.jar is that after is debug version, created past times compiling origin file using javac -g command. They include to a greater extent than debugging information, useful piece troubleshooting.
  • If you lot are connecting to Oracle 10g database from Java 1.4 or Java five thus move ojdbc14.jar or ojdbc14_g.jar files.
  • If your Java computer program is connecting to Oracle 10g database too running on Java 1.2 or Java 1.3 thus delight use classes12.jar and classes12_g.jar. Again deviation betwixt thus is only additional debug information.

That's all nearly how to solve java.lang.ClassNotFoundException: oracle.jdbc.OracleDriver mistake inwards Java. In 99% cases this mistake is solved past times putting correct Oracle driver JAR into classpath, but if you lot notwithstanding non able to solve this problem, thus I propose to banking concern stand upwards for for whatever classpath final result e.g. sometime you lot are putting it into a directory which is non included inwards CLASSPATH or another setting is overriding your expected classpath. If you lot are unsure nearly how to bargain alongside that error, I propose reading my tutorial How Java CLASSPATH Works? That volition grade you lot proficient consider nearly where to human face for when classpath issues surfaces.

Further Learning
JSP, Servlets too JDBC for Beginners: Build a Database App
Complete JDBC Programming Part 1 too 2
guide]
  • How to solve java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver inwards Java? [solution]
  • How to fix java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver inwards Java? [solution]
  • How to develop java.lang.ClassNotFoundException: org.postgresql.Driver mistake inwards Java? [solution]
  • How to solve java.lang.ClassNotFoundException:org.Springframework.Web.Context.ContextLoaderListener [solution]
  • How to solve java.lang.ClassNotFoundException: com.mysql.jdbc.Driver inwards Java MySQL? [solution]
  • java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory? [solution]
  • How to connect to MySQL database from Java Program [steps]
  • No comments:

    Post a Comment