This is my code for which I am getting error. My classes12.jar
has been imported as an external jar.
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class LoginAction extends HttpServlet {
Connection conn;
Statement stmt;
ResultSet rs;
String query = "SELECT * FROM v_urja_login";
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter out = response.getWriter();
out.println("Hello");
String u_name = request.getParameter("uname");
String u_pass = request.getParameter("upass");
out.println(u_name);
out.println(u_pass);
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","urja","urja");
stmt = conn.createStatement();
rs = stmt.executeQuery(query);
}catch(SQLException sex){
sex.printStackTrace();
} catch (ClassNotFoundException cnf) {
cnf.printStackTrace();
}
}
}
Stacktrace:
java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at LoginAction.doPost(LoginAction.java:27)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:931)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)
asked Mar 24, 2013 at 12:59
3
Class.forName("oracle.jdbc.driver.OracleDriver");
This line causes ClassNotFoundException
, because you haven’t placed ojdbc14.jar
file in your lib folder of the project. or YOu haven’t set the classpath
of the required jar
answered Mar 24, 2013 at 13:13
PragnaniPragnani
20.1k6 gold badges49 silver badges74 bronze badges
3
java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
Just add the ojdbc14.jar to your classpath.
The following are the steps that are given below to add ojdbc14.jar in eclipse:
1) Inside your project
2) Libraries
3) Right click on JRE System Library
4) Build Path
5) Select Configure Build Path
6) Click on Add external JARs…
7) C:oraclexeapporacleproduct10.2.0serverjdbclib
Here you will get ojdbc14.jar
9) select here
10) open
11) ok
save and run the program you will get output.
answered Mar 25, 2013 at 7:46
Karthik ReddyKarthik Reddy
2,8821 gold badge18 silver badges8 bronze badges
In Eclipse , rightclick on your application
Run As -> Run configurations -> select your server from type filter text box
Then in Classpath under Bootstrap Entries add your classes12.jar File and Click on Apply.
Now, run the file…… This worked for me !!
answered Jul 7, 2016 at 18:17
Ampati HareeshAmpati Hareesh
1,8521 gold badge14 silver badges20 bronze badges
0
Method 1: Download ojdbc.jar
add ojdbc6.jar to deployment assembly. Right click on project->properties->select deployment assembly->click on ‘Add’ ->select ‘Archives from File System’->browse to the folder where ojdbc6.jar is saved.->add the jar->click finish->Apply/OK.
Method 2:
if you want to add ojdbc.jar to your maven dependencies you follow this link: http://www.mkyong.com/maven/how-to-add-oracle-jdbc-driver-in-your-maven-local-repository/
.
.
Even if you’re using a maven project it is not necessary to add ojdbc to maven dependencies(method 2), method 1 (adding directly to deployment assembly) works just fine.
answered May 20, 2016 at 6:26
1
try to add ojdbc6.jar or other version through the server lib «C:apache-tomcat-7.0.47lib»,
Then restart the server in eclipse.
answered Jul 16, 2015 at 11:21
zedtimizedtimi
3061 silver badge6 bronze badges
1.Right click on your java project.
2.Select «RUN AS».
3.Select «RUN CONFIGURATIOS…».
4.Here select your server at left side of the page and then u would see «CLASS PATH» tab at riht side,just click on it.
5.Here clilck on «USER ENTRIES» and select «ADD EXTERNAL JARS».
6.Select «ojdbc14.jar» file.
7.Click on Apply.
8.Click on Run.
9.Finally Restart your server then it would be execute.
answered Jan 27, 2017 at 6:44
In Eclipse,
When you use JDBC in your servlet, the driver jar must be placed in the WEB-INF/lib directory of your project.
answered Jun 28, 2018 at 16:03
Not faced the issue ,After added Ojdbc8 dependency in the pom file.
answered Jan 19 at 10:59
You can add a JAR which having above specified class exist e.g.ojdbc jar which supported by installed java version, also make sure that you have added it into classpath.
answered Sep 20, 2017 at 5:16
CodeNinjaCodeNinja
791 silver badge4 bronze badges
Thank you for your response Polina Osipova. I figured out the problem, here are the details which might help others:
1. The server where Thingworx was installed didn’t had ojdbc6.jar file under Tomcatlib folder. Once file is added make sure server is restarted
2. Once the ojdbc6.jar extension is imported into Thingworkx composer, the configuration section holds the following entries:
JDBC Driver Class Name: oracle.jdbc.OracleDriver
JDBC Connection String: jdbc:oracle:thin:@//s.com:po
Disclosure: This article may contain affiliate links. When you purchase, we may earn a commission.
Scenario : Your Java program, either standalone or Java web application is trying to connect to Oracle database using type 4 JDBC thin driver «oracle.jdbc.driver.oracledriver», JVM is not able to find this class at runtime. This JAR comes in ojdbc6.jar or ojdbc6_g.jar which is most probably not available in classpath.
Cause : When you connect to Oracle database from Java program, your program loads the implementation of Driver interface provided by the database vendor using class.forName() method, which throws ClassNotFoundException when driver class is not found in classpath. In case of Oracle the driver implementation is oracle.jdbc.driver.oracledriver and «java.lang.classnotfoundexception oracle.jdbc.driver.oracledriver» error indicate that this class is not available in classpath. Since this class is bundled into ojdbc6.jar, its usually the case of this JAR not present in Classpath
As I said this error may come even if you are connecting to Oracle database from web server like Tomcat. This is the stack-trace from Tomcat, when my Java app was failed to load this class :
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 can see that due to a call to Class.forName(), WebappClassLoader tries to load this class file, it only looks at WEB-INF/lib directory, so if this class is not present in any JAR file at that location then it will throw java.lang.classnotfoundexception oracle.jdbc.driver.oracledriver
How to solve java.lang.ClassNotFoundException: oracle.jdbc.OracleDriver
Solution : If you already have this JAR then include this in your classpath, for example if you are running core Java application using main() method then just make sure that you use a custom classpath specified by -cp or -classpath parameter to java command and location of this JAR there.
If you are connecting to oracle database using Java web application (Servlet, JSP) then make sure that this JAR is present in WEB-INF/lib folder. If you are using tomcat to deploy your Java web application, You can also put this ojdbc.jar in apache-tomcat/lib directory, but remember that then it will not be loaded by WebAppClassLoader but its parent, which means it will be available to all web application and will not be unloaded when you remove your web application.
If you don’t have ojdbc6.jar or ojdbc_g.jar then download them from http://www.oracle.com/technetwork/database/enterprise-edition/jdbc-112010-090769.html, both contains oracle.jdbc.driver.oracledriver, only difference is that ojdbc_g.jar has been compiled using Javac -g parameter to include more debug information, useful while debugging and printing stacktrace. Once you add this JAR file in your application’s classpath there will be no more java.lang.classnotfoundexception oracle.jdbc.driver.oracledriver error in Java
Where to download Oracle 11g and 10g JDBC driver JARs
Oracle driver, oracle.jdbc.driver.oracledriver is available in ojdbc6.jar and ojdbc_g.jar for Oracle 11g, but if you are connecting to Oracle 10g database and running on Java 1.4 or Java 1.5 then you should either use ojdbc14.jar, or use classes12.jar if your Java application is running on JDK 1.2 and JDK 1.3. Though I suggest to use debug JAR files e.g. ojdbc14_g.jar or classes12_g.jar because they are compiled using javac -g option and contain useful tracing information.
You can download Oracle JDBC driver Jar files from http://www.oracle.com/technetwork/apps-tech/jdbc-10201-088211.html. ojdbc6.jar contain classes for use with Java 1.6 version, so if your application is running on Java 6 and connecting to Oracle 11g database then use ojdbc6 and ojdbc6_g.jar. If your program is running on Java 5 and connecting ot Oracle 11g then use ojdbc5.jar or ojdbc5_g.jar. You can download Oracle 11g JDBC drive JAR files from http://www.oracle.com/technetwork/apps-tech/jdbc-112010-090769.html.
Summary
- If you are connecting to Oracle 11g from Java and running on version Java 6 then include ojdbc6.jar or ojdbc6_g.jar in your application’s classpath.
- If you are connecting to Oracle 11g from Java 5 then include ojdbc5.jar or ojdbc5_g.jar in your application’s classpath.
- Difference between ojdbc6.jar and ojdbc6_g.jar is that later is debug version, created by compiling source file using javac -g command. They include more debugging information, useful while troubleshooting.
- If you are connecting to Oracle 10g database from Java 1.4 or Java 5 then use ojdbc14.jar or ojdbc14_g.jar files.
- If your Java program is connecting to Oracle 10g database and running on Java 1.2 or Java 1.3 then please use classes12.jar and classes12_g.jar. Again difference between then is just additional debug information.
That’s all about how to solve java.lang.ClassNotFoundException: oracle.jdbc.OracleDriver error in Java. In 99% cases this error is solved by putting right Oracle driver JAR into classpath, but if you still not able to solve this problem, then I suggest to check for any classpath issue e.g. sometime you are putting it into a directory which is not included in CLASSPATH or some other setting is overriding your expected classpath. If you are unsure about how to deal with that error, I suggest reading my tutorial How Java CLASSPATH Works? That will give you good idea about where to look for when classpath issues surfaces.
You can also check following articles if you are facing any issue while connecting to other popular database e.g. Oracle, SQL Server and MySQL from Java programs :
- General Guide to solve java.lang.ClassNotFoundException in Java [guide]
- How to solve java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver in Java? [solution]
- How to fix java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver in Java? [solution]
- How to fix java.lang.ClassNotFoundException: org.postgresql.Driver error in Java? [solution]
- How to solve java.lang.ClassNotFoundException:org.Springframework.Web.Context.ContextLoaderListener [solution]
- How to solve java.lang.ClassNotFoundException: com.mysql.jdbc.Driver in Java MySQL? [solution]
- java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory? [solution]
- How to connect to MySQL database from Java Program [steps]
I am using mybatis-migrations 3.1.1 (3.3.1 same behavior) and have followed installation instructions. I am using Oracle DB and trying to use ojdbc7 (or driver to connect to my database. I have JDK8 installed
ls -la:
svscorp@vm:~/mybatis$ pwd
/home/svscorp/mybatis
svscorp@vm:~/mybatis$ ls -la
drwxr-xr-x 8 svscorp svscorp 4096 Oct 4 16:59 .
drwxr-xr-x 8 svscorp svscorp 4096 Oct 4 16:50 ..
drwxr-xr-x 2 svscorp svscorp 4096 May 2 00:35 bin
drwxr-xr-x 2 svscorp svscorp 4096 Oct 4 16:54 drivers
drwxr-xr-x 2 svscorp svscorp 4096 Oct 4 16:50 environments
drwxr-xr-x 2 svscorp svscorp 4096 Oct 4 16:55 lib
-rw-rw-rw- 1 svscorp svscorp 11358 Apr 25 2016 LICENSE
-rw-rw-rw- 1 svscorp svscorp 2599 Apr 25 2016 NOTICE
-rw-rw-rw- 1 svscorp svscorp 3042 Apr 25 2016 README.md
drwxr-xr-x 2 svscorp svscorp 4096 Oct 4 16:59 scripts
more info on ENV VARS
svscorp@vm:~/mybatis$ echo $MIGRATIONS
/home/svscorp/mybatis/bin
svscorp@vm:~/mybatis$ echo $MIGRATIONS_HOME
/home/svscorp/mybatis
svscorp@vm:~/mybatis$ echo $PATH
/home/svscorp/mybatis/bin:<other-stuff>
development.properties
time_zone=GMT+0:00
driver="oracle.jdbc.OracleDriver"
url="jdbc:oracle:thin:@//[IP]:[PORT]/[DB]"
username=[USERNAME]
password=[USERNAME]
full_line_delimiter=false
auto_commit=false
In the drivers I have ojdbc8.jar (tried with ojdbc7.jar — same result).
Error message (—trace):
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option PermSize=128m; support was removed in 8.0
------------------------------------------------------------------------
-- MyBatis Migrations - status
------------------------------------------------------------------------
ID Applied At Description
================================================================================
------------------------------------------------------------------------
-- MyBatis Migrations FAILURE
-- Total time: 0s
-- Finished at: Wed Oct 04 17:04:15 CEST 2017
-- Final Memory: 10M/483M
------------------------------------------------------------------------
ERROR: Could not create SqlRunner. Cause: java.sql.SQLException: Error setting driver on UnpooledDataSource. Cause: java.lang.ClassNotFoundException: Cannot find class: "oracle.jdbc.OracleDriver"org.apache.ibatis.migration.MigrationException: Could not create SqlRunner. Cause: java.sql.SQLException: Error setting driver on UnpooledDataSource. Cause: java.lang.ClassNotFoundException: Cannot find class: "oracle.jdbc.OracleDriver"
at org.apache.ibatis.migration.operations.DatabaseOperation.getSqlRunner(DatabaseOperation.java:88)
at org.apache.ibatis.migration.operations.DatabaseOperation.changelogExists(DatabaseOperation.java:73)
at org.apache.ibatis.migration.operations.StatusOperation.operate(StatusOperation.java:44)
at org.apache.ibatis.migration.commands.StatusCommand.execute(StatusCommand.java:30)
at org.apache.ibatis.migration.CommandLine.runCommand(CommandLine.java:65)
at org.apache.ibatis.migration.CommandLine.execute(CommandLine.java:42)
at org.apache.ibatis.migration.Migrator.main(Migrator.java:20)
Caused by: java.sql.SQLException: Error setting driver on UnpooledDataSource. Cause: java.lang.ClassNotFoundException: Cannot find class: "oracle.jdbc.OracleDriver"
at org.apache.ibatis.datasource.unpooled.UnpooledDataSource.initializeDriver(UnpooledDataSource.java:221)
at org.apache.ibatis.datasource.unpooled.UnpooledDataSource.doGetConnection(UnpooledDataSource.java:200)
at org.apache.ibatis.datasource.unpooled.UnpooledDataSource.doGetConnection(UnpooledDataSource.java:196)
at org.apache.ibatis.datasource.unpooled.UnpooledDataSource.getConnection(UnpooledDataSource.java:93)
at org.apache.ibatis.migration.DataSourceConnectionProvider.getConnection(DataSourceConnectionProvider.java:34)
at org.apache.ibatis.migration.operations.DatabaseOperation.getSqlRunner(DatabaseOperation.java:86)
... 6 more
Same goes if I try older format specifying the driver: oracle.jdbc.driver.OracleDriver
Where did it go wrong?
2 Answers
Sorted by:
Reset to default
3
As per Let’s Start chapter of JMeter Getting Started Guide
If you want to perform JDBC testing, then you will, of course, need the appropriate JDBC driver from your vendor. JMeter does not come with any JDBC drivers.
So make sure to download Oracle JDBC Driver and drop it to JMeter Classpath.
And don’t forget to restart JMeter to pick the .jar up.
Also change «Validation Query» in the JDBC Connection Configuration to select 1 from dual
More information: The Real Secret to Building a Database Test Plan With JMeter
Improve this answer
answered Mar 16, 2020 at 14:45
Dmitri TDmitri T
13.1k1 gold badge14 silver badges18 bronze badges
Add a comment
|
0
Copy the jars you want to use and drop in this location:
JMETER_HOME/lib
Then restart jmeter.
Improve this answer
answered Mar 16, 2020 at 20:23
ToastManToastMan
3802 silver badges8 bronze badges
Add a comment
|
Your Answer
Sign up or log in
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Name
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.
Not the answer you’re looking for? Browse other questions tagged
- java
- jmeter
- sql
or ask your own question.
Not the answer you’re looking for? Browse other questions tagged
- java
- jmeter
- sql
or ask your own question.
Disclosure: This article may contain affiliate links. When you purchase, we may earn a small commission.
java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver Exception comes when you try to connect the Oracle database from Java program and Oracle driver is not available in Classpath. We have already seen How to connect Oracle database from Java program and found that, In order to connect to Oracle database, we load and register driver using Class.forName(«oracle.jdbc.driver.OracleDriver») and this code loads a class at runtime using Reflection which throws ClassNotFoundException if the class in question e.g. «oracle.jdbc.driver.OracleDriver» is not found.
I have already listed various reasons of ClassNotFoundExcepiton in Java, which is also applicable in this case. By the way java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver is similar to java.lang.ClassNotFoundException: MySQL.jdbc.driver.MySQLDriver which comes if you try to connect MySQL database from Java program and the corresponding driver is not in your classpath.
You can refer a link for getting more ideas that can be used to fix java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver error as well.
How to solve java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
In order to solve java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver, we need these classes either in the form of JAR or classes in your application classpath.
For Oracle 10g and 11g, these are present in ojdbc6.jar or ojdbc6_g.jar, which are the same except later is compiled with javac -g option to include debug information and tracking code. If you don’t have this JAR then you can download it from http://www.oracle.com/technetwork/database/enterprise-edition/jdbc-112010-090769.html.
Just download this JAR file and add into your Classpath by following steps given in How to set Classpath in Java. If you are not very comfortable with setting classpath then you can also put this JAR file in JRE/ext directory C:Program FilesJavajdk1.6.0_20jrelibext which is used by extension class loader to load a class file.
Though it’s not advisable and you should only do this for testing as chances of leaving that ojdbc6.jar are more which may cause in future if you have a new version of driver somewhere else in Application classpath but your Java application still picking these old drivers. See How the classloader works in Java for more details on this issue.
That’s all on How to fix java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver in Java. This is like any other standard java.lang.ClassNotFoundException except that you should know on which JAR file you can find this driver i.e. ojdbc6.jar.
If you are using Eclipse then you can just include this JAR in your build path by selecting a project, right-click, properties, Java Build Path, and then adding JAR on the libraries tab. You can even verify whether oracle.jdbc.driver.OracleDriver is in your Classpath or not by using Eclipse shortcut for checking classes in project classpath.
Other debugging and troubleshooting articles from Javarevisited Blog
How to fix java.lang.UnsupportedClassVersionError in Java
Skip to content
Solving the problem with connecting the jdbc driver for Oracle in Maven. Although the repositories have configs for the Oracle driver, they are not pulled into the project.
When trying to connect to an Oracle database: java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
The solution is simple. You need to download the current version of the driver from the Oracle website (for the database version): Oracle Database JDBC Driver
Install the driver in your local repository:
java -cp pathojdbc7.jar oracle.jdbc.OracleDriver
Then connect the driver in the standard way in pom.xml
Oracle Jdbc connect bean for Spring & ibatis