java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver

Symptom)
I made a sample servlet web application. The application works along with Oracle DBMS. I tried connecting to DB using jdbc programming. When the application was running, I got the error message below.
java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
2. Servlet doGet() stop
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1358)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1180)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at UserDao.getUser(UserDao.java:26)
at LoginServlet.doPost(LoginServlet.java:30)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:660)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)

Root Cause)
I forgot to import jdbc library to the web application project.
So, solution is just add jdbc library to your project. There are 2 ways to do it.

Solution1)


Step1. Go to your eclipse IDE and right click your project. Click [Properties].


Step2. Select [Java Build Path] and click [Add External JARs...].


Step3. Go to "E:/app/users/product/11.2.0/dbhome_1/jdbc/lib" and select "ojdbc5.jar" or "ojdbc6.jar". And then, click [Open]
Make sure that which version is correct to select. it is depending on the installed Java version and created Servlet version.
Also, keep in mind that location of ojdbc.jar file is different as Oracle DB installation root folder is different.


Step4. Check that "ojdbc6.jar" is added in the tree list viewer. Click [Apply and Close].


Solution2)

Step1. Go to "E:/app/users/product/11.2.0/dbhome_1/jdbc/lib". Select and Copy "ojdbc5.jar" or "ojdbc6.jar".


Step2. In eclipse IDE, click [Window] menu. Click [Preferences]


Step3. Select [Java] and [Installed JREs]. Check the installed JRE_HOME  Location value.


Step4. Paste "ojdbc6.jar" in the JRE_HOME/lib/ext.









Comments

Popular posts from this blog

$$ Regular Expression이 안먹는 경우

[Java] Install JDK and configure Environment variable

exception in thread main java.lang.unsupportedclassversionerror unsupported major.minor version 52.0