Oracle Jdbc Driver Name

The Oracle JDBC driver class that implements the java.sql.Driver interface.

To access a database from a Java application, you must first provide the code to register your installed driver with your program. You do this with the static registerDriver() method of the java.sql.DriverManager class. This class provides a basic service for managing a set of JDBC drivers. The registerDriver() method takes as input a 'driver' class, that is, a class that implements the java.sql.Driver interface, as is the case with OracleDriver.

Note: Alternatively, you can use the forName() method of the java.lang.Class class to load the JDBC drivers directly. For example: Class.forName ('oracle.jdbc.OracleDriver');. However, this method is valid only for JDK-compliant Java virtual machines. It is not valid for Microsoft Java virtual machines.

Register JDBC Driver. You must register the driver in your program before you use it. Registering the driver is the process by which the Oracle driver's class file is loaded into the memory, so it can be utilized as an implementation of the JDBC interfaces. You need to do this registration only once in your program.

Extends oracle.jdbc.driver.OracleDriver. The Oracle JDBC driver class that implements the java.sql.Driver interface. Register the JDBC drivers. To access a database from a Java application, you must first provide the code to register your installed driver with your program. You do this with the static registerDriver method of the java.sql.DriverManager class. This class provides a basic service for managing a set of JDBC drivers. Public class OracleDriver extends oracle.jdbc.driver.OracleDriver. The Oracle JDBC driver class that implements the java.sql.Driver interface. Register the JDBC drivers. To access a database from a Java application, you must first provide the code to register your installed driver with your program. A JDBC example to show you how to connect to a Oracle database with a JDBC driver. Tested with: Java 8; Oracle database 19c; Oracle JDBC driver for Java 8, ojdbc8.jar; 1. Download Oracle JDBC Driver. Visit Oracle database website and download the Oracle JDBC Driver. JDBC Driver Class Not Found: oracle.jdbc.OracleDriver. I'm trying to setup a connection to ORACLE 12c. I uploaded the JAR file using TWDownloadJDBC Connector Extension. Any help appreciated.

You register the driver only once in your Java application.

Once you have registered the driver, you can open a connection to the database with the static getConnection() method of the java.sql.DriverManager class. The type of the object returned is java.sql.Connection.

Understanding the Forms of getConnection()

Specifying a Databse URL, User Name, and Password

The following signature takes the URL, user name, and password as separate parameters:

getConnection(String URL, String user, String password);

Where the URL is of the form:
jdbc:oracle:<drivertype>:@<database>

The following example connects user scott with password tiger to a database with SID orcl through port 1521 of host myhost, using the Thin driver.

Connection conn = DriverManager.getConnection
('jdbc:oracle:thin:@myhost:1521:orcl', 'scott', 'tiger');

Specifying a Databse URL That Includes User Name and Password

The following signature takes the URL, user name, and password all as part of a URL parameter:

getConnection(String URL);

Where the URL is of the form:
jdbc:oracle:<drivertype>:<user>/<password>@<database>

The following example connects user scott with password tiger to a database on host myhost using the OCI driver. In this case, however, the URL includes the userid and password, and is the only input parameter.

Connection conn = DriverManager.getConnection
('jdbc:oracle:oci8:scott/tiger@myhost);

If you want to connect with the Thin driver, you must specify the port number and SID. For example, if you want to connect to the database on host myhost that has a TCP/IP listener up on port 1521, and the SID (system identifier) is orcl:

Connection conn = DriverManager.getConnection
('jdbc:oracle:thin:scott/tiger@myhost:1521:orcl);

Specifying a Database URL and Properties Object

The following signature takes a URL, together with a properties object that specifies user name and password (perhaps among other things):

getConnection(String URL, Properties info);

Where the URL is of the form:
jdbc:oracle:<drivertype>:@<database>

In addition to the URL, use an object of the standard Java Properties class as input. For example:

java.util.Properties info = new java.util.Properties();
info.put ('user', 'scott');
info.put ('password','tiger');
info.put ('defaultRowPrefetch','15');
getConnection ('jdbc:oracle:oci8:@',info);

The table below lists the connection properties that Oracle JDBC drivers support.

Connection Properties Recognized by Oracle JDBC Drivers

NameShort NameTypeDescription
user n/a String the user name for logging into the database
password n/a String the password for logging into the database
database server String the connect string for the database
internal_logon n/a String a role, such as sysdba or sysoper, that allows you to log on as sys
defaultRowPrefetch prefetch String (containing integer value) the default number of rows to prefetch from the server (default value is '10')
remarksReporting remarks String (containing boolean value) 'true' if getTables() and getColumns() should report TABLE_REMARKS; equivalent to using setRemarksReporting() (default value is 'false')
defaultBatchValue batchvalue String (containing integer value) the default batch value that triggers an execution request (default value is '10')
includeSynonyms synonyms String (containing boolean value) 'true' to include column information from predefined 'synonym' SQL entities when you execute a DataBaseMetaData getColumns() call; equivalent to connection setIncludeSynonyms() call (default value is 'false')
processEscapes n/a String (containing boolean value) 'false' to disable escape processing for statements (Statement or PreparedStatement) created from this connection. Set this to 'false' if you want to avoid many calls to Statement.setEscapeProcessing(false);. This is espcially usefull for PreparedStatement where a call to setEscapeProcessing(false) would have no effect. The default is 'true'.
defaultNChar n/a String (containing boolean value) 'false' is the default. If set to 'true', the default behavior for handling character datatypes is changed so that NCHAR/NVARCHAR2 become the default. This means that setFormOfUse() won't be needed anymore when using NCHAR/NVARCHAR2. This can also be set as a java property :
java -Doracle.jdbc.defaultNChar=true myApplication
useFetchSizeWithLongColumn n/a String (containing boolean value) 'false' is the default.
THIS IS A THIN ONLY PROPERTY. IT SHOULD NOT BE USED WITH ANY OTHER DRIVERS.
If set to 'true', the performance when retrieving data in a 'SELECT' will be improved but the default behavior for handling LONG columns will be changed to fetch multiple rows (prefetch size). It means that enough memory will be allocated to read this data. So if you want to use this property, make sure that the LONG columns you are retrieving are not too big or you may run out of memory. This property can also be set as a java property :
java -Doracle.jdbc.useFetchSizeWithLongColumn=true myApplication
SetFloatAndDoubleUseBinary n/a String (containing boolean value) 'false' is the default.
If set to 'true', causes the java.sql.PreparedStatment setFloat and setDouble API's to use internal binary format as for BINARY_FLOAT and BINARY_DOUBLE parameters.
See oracle.jdbc.OraclePreparedStatement setBinaryFloat and setBinaryDouble
Oracle Jdbc Driver Name

Select your driver type : thin, oci, kprb..

Oralce provides four types of JDBC driver.

  • Thin Driver, a 100% Java driver for client-side use without an Oracle installation, particularly with applets. The Thin driver type is thin. To connect user scott with password tiger to a database with SID (system identifier) orcl through port 1521 of host myhost, using the Thin driver, you would write :
  • OCI Driver for client-side use with an Oracle client installation. The OCI driver type is oci. To connect user scott with password tiger to a database with SID (system identifier) orcl through port 1521 of host myhost, using the OCI driver, you would write : Note that you can also specify the database by a TNSNAMES entry. You can find the available TNSNAMES entries listed in the file tnsnames.ora on the client computer from which you are connecting. For example, if you want to connect to the database on host myhost as user scott with password tiger that has a TNSNAMES entry of MyHostString, enter: If your JDBC client and Oracle server are running on the same machine, the OCI driver can use IPC (InterProcess Communication) to connect to the database instead of a network connection. An IPC connection is much faster than a network connection.
  • Server-Side Thin Driver, which is functionally the same as the client-side Thin driver, but is for code that runs inside an Oracle server and needs to access a remote server, including middle-tier scenarios. The Server-Side Thin driver type is thin and there is no difference in your code between using the Thin driver from a client application or from inside a server.
  • Server-Side Internal Driver for code that runs inside the target server, that is, inside the Oracle server that it must access. The Server-Side Internal driver type is kprb and it actually runs within a default session. You are already 'connected'. Therefore the connection should never be closed.
    To access the default connection, write: You can also use the Oracle-specific defaultConnection() method of the OracleDriver class which is generally recommended: Note: You are no longer required to register the OracleDriver class for connecting with the Server-Side Internal driver, although there is no harm in doing so. This is true whether you are using getConnection() or defaultConnection() to make the connection.
    Any user name or password you include in the URL string is ignored in connecting to the server default connection. The DriverManager.getConnection() method returns a new Java Connection object every time you call it. Note that although the method is not creating a new physical connection (only a single implicit connection is used), it is returning a new object.
    Again, when JDBC code is running inside the target server, the connection is an implicit data channel, not an explicit connection instance as from a client. It should never be closed.
Field Summary
static java.lang.StringBUILD_DATE
static booleanTRACE
Fields inherited from class oracle.jdbc.driver.OracleDriver
access_string, accumulate_batch_result, batch_string, convert_nchar_literals_string, database_string, dataSizeBytes, dataSizeChars, dataSizeUnitsPropertyName, default_execute_batch_string, default_row_prefetch_string, defaultnchar_string, defaultncharprop_string, disable_defineColumnType_string, dll_string, execute_batch_string, fixed_string_string, include_synonyms_string, j2ee_compliance, jdbc_string, logon_as_internal_str, nls_lang_backdoor, no_caching_buffers, oracle_string, password_string, permit_timestamp_date_mismatch_string, prefetch_string, prelim_auth_string, process_escapes_string, protocol_string, protocolFullName_string, proxy_client_name, read_timeout, remarks_string, report_remarks_string, restrict_getTables_string, retain_v9_bind_behavior_string, row_prefetch_string, server_string, set_new_password_string, SetFloatAndDoubleUseBinary_string, StreamChunkSize_string, synonyms_string, systemTypeMap, tcp_no_delay, useFetchSizeWithLongColumn_prop_string, useFetchSizeWithLongColumn_string, user_string, v8compatible_string, xa_trans_loose
Constructor Summary
OracleDriver()
Method Summary
static java.lang.StringgetBuildDate()
Returns a String that specifies exactly when the jar file was built.
static java.lang.StringgetDriverVersion()
Returns a String that specifies the Oracle version number of the driver.
static java.lang.StringgetJDBCVersion()
Returns a String that specifies the version of the JDBC spec supporte by the driver.
static booleanisDebug()
Returns true if this jar includes debug code.
static booleanisDMS()
Returns true if this jar includes DMS instrumentaion.
static booleanisInServer()
Returns true if this jar was built to run in the Oracle Java VM.
static booleanisJDK14()
Deprecated.
static booleanisPrivateDebug()
Returns true if this jar includes Oracle internal debug code.
static voidmain(java.lang.String[] args)
Prints a description of the Oracle JDBC driver .jar file to System.out.
Methods inherited from class oracle.jdbc.driver.OracleDriver
acceptsURL, connect, defaultConnection, getCompileTime, getMajorVersion, getMinorVersion, getPropertyInfo, getSystemPropertyFastConnectionFailover, jdbcCompliant, processSqlEscapes, registerMBeans
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Field Detail

BUILD_DATE

See Also:
Constant Field Values

TRACE

See Also:
Constant Field Values
Constructor Detail

OracleDriver

Method Detail

isDMS

Returns true if this jar includes DMS instrumentaion.
Returns:
true if DMS jar

isInServer

Returns true if this jar was built to run in the Oracle Java VM.
Returns:
true if server jar

isJDK14

Deprecated.
Returns true if this is a JDK 1.4 or later compliant jar. Since JDK 1.3 is desupported, always returns true.
Returns:
true

isDebug

Returns true if this jar includes debug code.
Returns:
true if debug jar

isPrivateDebug

Returns true if this jar includes Oracle internal debug code.
Returns:
true if private debug jar

getJDBCVersion

Returns a String that specifies the version of the JDBC spec supporte by the driver.
Returns:
JDBC spec version

getDriverVersion

Returns a String that specifies the Oracle version number of the driver.
Returns:
version number

getBuildDate

Returns a String that specifies exactly when the jar file was built.
Returns:
build date

main

Prints a description of the Oracle JDBC driver .jar file to System.out.
Parameters:
args - Ignored
Throws:
java.lang.Exception
OverviewPackageClassTreeDeprecatedIndexHelp
Oracle JDBC API Reference
11g Release 2 ('11.2.0.3.0')
FRAMESNO FRAMESAll Classes SUMMARY: NESTED | FIELD | CONSTR | METHODDETAIL: FIELD | CONSTR | METHOD
Copyright © 1998, 2007, Oracle. All rights reserved.
Oracle8i JDBC Developer's Guide and Reference
Release 8.1.5

A64685-01

Library

Product

Contents

Index

First Steps in JDBC

This section describes how to get up and running with the Oracle JDBC drivers. When using the Oracle JDBC drivers, you must include certain driver-specific information in your programs. This section describes, in the form of a tutorial, where and how to add the information. The tutorial guides you through creating code to connect to and query a database from the client.

To connect to and query a database from the client, you must provide code for these tasks:

  1. Importing Packages
  2. Registering the JDBC Drivers
  3. Opening a Connection to a Database
  4. Creating a Statement Object
  5. Executing a Query and Returning a Result Set Object
  6. Processing the Result Set
  7. Closing the Result Set and Statement Objects
  8. Closing the Connection

You must supply Oracle driver-specific information for the first three tasks, which allow your program to use the JDBC API to access a database. For the other tasks, you can use standard JDBC Java code as you would for any Java application.

Importing Packages

Regardless of which Oracle JDBC driver you use, you must include the following import statements at the beginning of your program.

You will need to add the following Oracle packages to your program when you want to access the extended functionality provided by the Oracle drivers. However, they are not required for the example presented in this section:

oracle.jdbc.driver.* and oracle.sql.*

Add these packages if you use any Oracle-specific extensions to JDBC in your program. For more information on Oracle extensions, see Chapter 4, 'Oracle Extensions'.

Oracle Jdbc Driver Name For Pc

Registering the JDBC Drivers

You must provide the code to register your installed driver with your program. You do this with the static registerDriver() method of the JDBC DriverManager class. This class provides a basic service for managing a set of JDBC drivers.

Note:

Alternatively, you can use the forName() method of the java.lang.Class class to load the JDBC drivers directly. For example:

Class.forName ('oracle.jdbc.driver.OracleDriver');

However, this method is valid only for JDK-compliant Java virtual machines. It is not valid for Microsoft Java virtual machines.

Because you are using one of Oracle's JDBC drivers, you declare a specific driver name string to registerDriver(). You register the driver only once in your Java application.

Note:

If you are registering a Thin driver in an applet, you must enter a driver string that is different from the one used in these examples. For more information on registering a Thin driver for an applet, see 'Coding Applets'.

Opening a Connection to a Database

You open a connection to the database with the static getConnection() method of the JDBC DriverManager class. This method returns an object of the JDBC Connection class which needs as input a userid, password, connect string that identifies the JDBC driver to use, and the name of the database to which you want to connect.

Oracle Jdbc Driver Class Name 11g

Connecting to a database is a step where you must enter Oracle JDBC driver-specific information in the getConnection() method. If you are not familiar with this method, continue reading the 'Understanding the Forms of getConnection()' section below.

If you are already familiar with the getConnection() method, you can skip ahead to either of these sections, depending on the driver you installed:

Understanding the Forms of getConnection()

The getConnection() method is an overloaded method that you declare by the techniques described in these sections:

  • 'Specifying a Database URL, Userid, and Password'
  • 'Specifying a Database URL That Includes Userid and Password'
  • 'Specifying a Database URL and Properties Object'

    Note:

    You do not have to specify the database name if there is a default connection. For more information about default connections, see 'Connecting to the Database with the Server Driver'.

If you want to specify a database name in the connection, it must be in one of the following formats:

  • a Net8 keyword-value pair
  • a string of the form <host_name>:<port_number>:<sid> (Thin driver only)
  • a TNSNAMES entry (OCI driver only)

For information on how to specify a keyword-value pair or a TNSNAMES entry, see yourNet8 Administrator's Guide.

Specifying a Database URL, Userid, and Password

where the URL is of the form:

The following example connects user scott with password tiger to a database with SID orcl through port 1521 of host myhost, using the Thin driver.

If you want to use the default connection for an OCI driver, specify either:

OR

For all JDBC drivers you can also specify the database with a Net8 keyword-value pair. The Net8 keyword-value pair substitutes for the TNSNAMES entry. The following example uses the same parameters as the preceding example, but in the keyword-value format:

OR

Specifying a Database URL That Includes Userid and Password

where the URL is of the form:

The following example connects user scott with password tiger to a database using the OCI driver. In this case, however, the URL includes the userid and password, and is the only input parameter.

Specifying a Database URL and Properties Object

where the URL is of the form:

In addition to the URL, use an object of the standard Java Properties class as input. For example:

Oracle Extensions to Connection Properties Object

Oracle has defined several extensions to the connection properties that Oracle JDBC drivers support. For more information on this form of the getConnection() method and the Oracle extensions to the Properties object, see 'Oracle Extensions for Connection Properties'.

Opening a Connection for the JDBC OCI Driver

For the JDBC OCI driver, you can specify the database by a TNSNAMES entry. You can find the available TNSNAMES entries listed in the file tnsnames.ora on the client computer from which you are connecting. On Windows NT this file is located in [ORACLE_HOME]NETWORKADMIN. On UNIX systems, you can find it in /var/opt/oracle.

Oracle jdbc driver class name 11g

For example, if you want to connect to the database on host myhost as user scott with password tiger that has a TNSNAMES entry of MyHostString, enter:

Note that both the ':' and '@' characters are necessary.

For the JDBC OCI driver (as with the Thin driver), you can also specify the database with a Net8 keyword-value pair. This is less readable than a TNSNAMES entry but does not depend on the accuracy of the TNSNAMES.ORA file. The Net8 keyword-value pair also works with other JDBC drivers.

For example, if you want to connect to the database on host myhost that has a TCP/IP listener up on port 1521, and the SID (system identifier) is orcl, use a statement such as:

Opening a Connection for the JDBC Thin Driver

Because you can use the JDBC Thin driver in applets that do not depend on an Oracle client installation, you cannot use a TNSNAMES entry to identify the database to which you want to connect. You have to either:

  • explicitly list the host name, TCP/IP port and Oracle SID of the database to which you want to connect

OR

  • use a keyword-value pair list

    Note:

    The JDBC Thin driver supports only the TCP/IP protocol.

For example, use this string if you want to connect to the database on host myhost that has a TCP/IP listener on port 1521 for the database SID (system identifier) orcl. You can logon as user scott, with password tiger:

You can also specify the database with a Net8 keyword-value pair. This is less readable than the first version, but also works with the other JDBC drivers.

('jdbc:oracle:thin:@(description=(address=(host=myhost)(protocol=tcp)
Note:

If you are writing a connection statement for an applet, you must enter a connect string that is different from the one used in these examples. For more information on connecting to a database with an applet, see 'Coding Applets'.

Creating a Statement Object

Once you connect to the database and, in the process, create your Connection object, the next step is to create a Statement object. The createStatement() method of your JDBC Connection object returns an object of the JDBC Statement class. To continue the example from the previous section where the Connection object conn was created, here is an example of how to create the Statement object:

Note that there is nothing Oracle-specific about this statement; it follows standard JDBC syntax. Png to jpg converter free download.

Oracle Jdbc Driver Class Name 12c

Executing a Query and Returning a Result Set Object

To query the database, use the executeQuery() method of your Statement object. This method takes a SQL statement as input and returns an object of the JDBC ResultSet class.

To continue the example, once you create the Statement object stmt, the next step is to execute a query that populates a ResultSet object with the contents of the ENAME (employee name) column of a table of employees that is named EMP:

Again, there is nothing Oracle-specific about this statement; it follows standard JDBC syntax.

Note:

The JDBC drivers actually return an OracleResultSet object, but into a standard ResultSet output variable. If you want to use Oracle extensions to process the result set, then you must cast the output to OracleResultSet. This is further discussed in 'Classes of the oracle.jdbc.driver Package'.

Processing the Result Set

Once you execute your query, use the next() method of your ResultSet object to iterate through the results. This method loops through the result set row by row, detecting the end of the result set when it is reached.

To pull data out of the result set as you iterate through it, use the various getXXX() methods of the ResultSet object, where XXX corresponds to a Java datatype.

For example, the following code will iterate through the ResultSet object rset from the previous section, and will retrieve and print each employee name:

Once again, this is standard JDBC syntax. The next() method returns false when it reaches the end of the result set. The employee names are materialized as Java Strings.

Closing the Result Set and Statement Objects

You must explicitly close the ResultSet and Statement objects after you finish using them. This applies to all ResultSet and Statement objects you create when using the Oracle JDBC drivers. The drivers do not have finalizer methods; cleanup routines are performed by the close() method of the ResultSet and Statement classes. If you do not explicitly close your ResultSet and Statement objects, serious memory leaks could occur. You could also run out of cursors in the database. Closing a result set or statement releases the corresponding cursor in the database.

For example, if your ResultSet object is rset and your Statement object is stmt, close the result set and statement with these lines:

When you close a Statement object that a given Connection object creates, the connection itself remains open.

Oracle Jdbc Driver Name 11g

Closing the Connection

You must close your connection to the database once you finish your work. Use the close() method of the Connection class to do this. For example, if your Connection object is conn, close the connection with this statement:


Prev

Top

Next

Copyright © 1999 Oracle Corporation.
All Rights Reserved.

Library

Product

Contents

Index

Oracle Jdbc Driver Download