- I want to add the oracle jdbc driver to my project as dependency (runtime scope) - ojdbc14. In MVNrepository site the dependency to put in the POM is.
- My professor asks us to make a java program that asks the user to input the data and the data inputted should automatically be inserted into a table in sql developer.
- The TAR archive contains the latest 12.1.0.2 JDBC Thin driver (ojdbc7.jar and ojdbc6.jar), Universal Connection Pool (ucp.jar), other companion jars, and README that has more information about the contents of the tar file.
This JDBC Java tutorial describes how to use JDBC API to create, insert into, update, and query tables. You will also learn how to use simple and prepared statements, stored procedures and. This page lists JDBC driver, UCP and other necessary jar files for various supported versions of Oracle Database.
Oracle Jdbc Driver Class Name
The TAR archive contains the latest 11.2.0.4 JDBC Thin driver (ojdbc6.jar and ojdbc5.jar), Universal Connection Pool (ucp.jar), other companion jars, and README that has more information about the contents of the tar file.
Active3 years, 2 months ago
I have installed Oracle 11.2 and Java:
In the command line, if i try to:
Java says: impossibile to load or find oracle.jdbc.driver.OracleDriver
I have copied
ojdbc5.jar
, ojdbc6.jar
and ojdbc6_g.jar
From
oraclexeapporacleproduct11.2.0serverjdbclib
toC:Program FilesJavajdk1.7.0_09lib
If i run
echo %CLASSPATH%
I get:Any reasons why Java can't find
oracle.jdbc.driver.OracleDriver
? anon
4 Answers
You reference a folder on the classpath and expect it to load all jars in it. That is not how the classpath works, you need to reference specific jars (and normally you should NOT put third party jars inside the JDK folder).
It is also important to know that the
CLASSPATH
is usually ignored by java applications, except for the most basic use cases.You can do what you try to achieve by doing:
This will fail btw because
OracleDriver
has no public static void main(String[] args)
method and therefor cannot be run like this. The normal way to use a JDBC driver is to have the driver on the application classpath, and simply specify the right driver URL. JDBC 4.0 (Java 6) or higher compliant drivers will be automatically loaded from the classpath (as specified with -cp
, the Class-Path
manifest entry etc).On an unrelated note,
oracle.jdbc.driver.OracleDriver
is considered deprecated, use oracle.jdbc.OracleDriver
instead, see Difference between Oracle jdbc driver classes?Community♦
Mark RotteveelMark Rotteveel65.6k1414 gold badges8686 silver badges126126 bronze badges
Putting a directory on the classpath doesn't put all the jar files within that directory on the classpath. It's not clear why you've copied the Oracle jar file into your Java installation directory - I'd recommend not doing that - but you should just list the location explicitly. For example, if you've copied it into the
lib
directory relative to your application, you could use:You can use
*
in a -cp
command line argument to find all jar files, e.g.or you could copy it into an 'extensions' directory - but I think it's clearer to be explicit.
Jon SkeetJon Skeet1130k715715 gold badges81948194 silver badges85818581 bronze badges
I also had same problem and this is what i didI extracted ojdbc5.jar and then i copied oracle folder in extracted ojdbc5.jar and then pasted in current location where i wrote jdbc program ( not mentioning the directory as it differs from programmer to programmer), then used import oracle.jdbc.*; statement in my jdbc program as oracle.jdbc has OracleDriver in it.Rest of the program is same
NavyanthNavyanth
Before copying
Theodore Norvellojdbc6.jar
to <jdk-home>/jre/lib/ext/
, in IDEA you need to add the ojdbc6.jar
file in 'Structure' -> 'SDK' -> 'add classpath' to <jdk-home>/jre/lib/ext/ojdbc6.jar
7,89744 gold badges1919 silver badges3737 bronze badges
MihailMihail
Active2 years, 4 months ago
What will the command
exactly do while connecting to a Oracle database? Is there an alternate way of doing the same thing?
Mark Rotteveel65.6k1414 gold badges8686 silver badges126126 bronze badges
AravindAravind1,18333 gold badges1717 silver badges2828 bronze badges
7 Answers
It obtains a reference to the class object with the FQCN (fully qualified class name)
oracle.jdbc.driver.OracleDriver
.It doesn't 'do' anything in terms of connecting to a database, aside from ensure that the specified class is loaded by the current classloader. There is no fundamental difference between writing
Class.forName('com.example.some.jdbc.driver')
calls show up in legacy code that uses JDBC because that is the legacy way of loading a JDBC driver.From The Java Tutorial:
In previous versions of JDBC, to obtain a connection, you first had to initialize your JDBC driver by calling the method
...
Any JDBC 4.0 drivers that are found in your class path are automatically loaded. (However, you must manually load any drivers prior to JDBC 4.0 with the method
Class.forName
. This methods required an object of type java.sql.Driver
. Each JDBC driver contains one or more classes that implements the interface java.sql.Driver
....
Any JDBC 4.0 drivers that are found in your class path are automatically loaded. (However, you must manually load any drivers prior to JDBC 4.0 with the method
Class.forName
.)Further reading (read: questions this is a dup of)
Community♦
Matt BallMatt Ball292k7878 gold badges571571 silver badges642642 bronze badges
McDowellMcDowell96.8k2424 gold badges180180 silver badges252252 bronze badges
From the Java JDBC tutorial:
In previous versions of JDBC, to obtain a connection, you first had to initialize your JDBC driver by calling the method
Class.forName
. Any JDBC 4.0 drivers that are found in your class path are automatically loaded. (However, you must manually load any drivers prior to JDBC 4.0 with the method Class.forName
.)So, if you're using the Oracle 11g (11.1) driver with Java 1.6, you don't need to call
JonathanClass.forName
. Otherwise, you need to call it to initialise the driver.![Jdbc Jdbc](/uploads/1/2/6/2/126215311/506808014.gif)
5,94133 gold badges2424 silver badges4343 bronze badges
This command loads class of Oracle jdbc driver to be available for DriverManager instance. After the class is loaded system can connect to Oracle using it. As an alternative you can use registerDriver method of DriverManager and pass it with instance of JDBC driver you need.
anatolichanatolich
Pre Java 6 the
DriverManager
class wouldn't have known which JDBC driver you wanted to use. Class.forName('...')
was a way on pre-loading the driver classes.If you are using Java 6 you no longer need to do this.
QwerkyQwerky15.8k55 gold badges3434 silver badges7373 bronze badges
An alternative would to use the jdbc.drivers System property to specify your required drivers(s) on the command line when you start the JVM.
sudocodesudocode
Use oracle.jdbc.OracleDriver, not oracle.jdbc.driver.OracleDriver. You do not need to register it if the driver jar file is in the 'WEB-INFlib' directory, if you are using Tomcat. Save this as test.jsp and put it in your web directory, and redeploy your web app folder in Tomcat manager:
TomTom