TestingDocs.com
Software Testing website
  • Automation
    • Selenium
    • JBehave Framework
  • Tutorials
    • MySQL Tutorials
    • Testlink
    • Maven
    • Git
  • IDEs
    • IntelliJ IDEA
    • Eclipse
  • Flowcharts
    • Flowgorithm
    • Raptor
  • About

JDBC

Connect to Oracle Database using JDBC Thin Driver

Overview

In this tutorial, we will learn the steps to connect to Oracle Database using JDBC Thin Driver in Java programming language. In this example, we will connect to SCOTT schema on a pluggable database named orclpdb.

Checklist

  • Oracle Database

Install the database, if you do not already have an Oracle Database installed. Sample steps to install Oracle on Windows operating system:

https://www.testingdocs.com/install-oracle-19c-database-on-windows-10/

For Detailed Steps follow the vendor’s instructions for the database installation.

  • JDK
  • Sample Scheme setup

Instructions to setup the sample SCOTT schema can be found here:

https://www.testingdocs.com/setting-up-sample-schema-in-oracle/

  • Oracle JDBC Thin Driver
  • Eclipse/ IntelliJ IDE

Oracle JDBC Thin Driver

The JDBC driver can be found at the following location on the database machine:

%ORACLE_HOME%\jdbc\lib

For standalone Java project add the JDBC jar file to the project build path.

Connection Descriptor

The connection descriptor string should be formed using the tnsnames.ora file from the database instance that we are trying to establish the connection. The exact hostname, port, and the service name can be found in the tnsnames.ora file.

On Windows the file can be found at the following path: %ORACLE_HOME%\network\admin

tnsnames File Oracle TestingDocs

Java Sample Program

 

import java.sql.*;
import oracle.jdbc.pool.OracleDataSource;

/*********************************************
 * Oracle JDBC Thin Driver Demo
 * Print JDBC Version Information
 * Java Tutorials - www.TestingDocs.com
 * 
 * @author testingdocs
 *
 *********************************************/
public class OracleThinJDBCVersion
{
 public static void main (String args[])
 throws SQLException
 {
 OracleDataSource ods = new OracleDataSource();
 ods.setURL("jdbc:oracle:thin:scott/tiger@
//localhost:1521/orclpdb.localdomain");
 Connection connection = ods.getConnection();
 // Create Oracle DatabaseMetaData Object
 DatabaseMetaData meta = connection
.getMetaData();
 // Display JDBC Driver Version Info
 System.out.println("Oracle JDBC Thin Driver
 Version: " + meta.getDriverVersion());
 }
}

Screenshot

The program connects to the Oracle database and prints the JDBC version on to the console window.

Oracle JDBC Thin Driver Java Program

 

—

Java Tutorials

Java Tutorial on this website:

https://www.testingdocs.com/java-tutorial/

For more information on Java, visit the official website :

https://www.oracle.com/java/

More information about Oracle Database:

https://www.oracle.com/database/

Related Posts

Display Oracle Database Table JDBC

JDBC /

Display data from Oracle Database table using JDBC

JDBC API TestingDocs

JDBC /

JDBC API Components

JDBC /

JDBC ResultSet Interface

Configure Build Path Eclipse

JDBC /

Configure JDBC Driver in Java Project

JDBC DriverManager Class

JDBC /

JDBC DriverManager Class

‹ Display data from Oracle Database table using JDBC

Recent Posts

  • Update draw.io on Windows
  • Install RAPTOR Avalonia on CentOS
  • Download RAPTOR Avalonia Edition on Windows
  • npm doctor command
  • Build & Run CLion Project
  • Create New CLion C Project on Windows
  • Configure CLion Toolchains on Windows
  • Launch CLion IDE on Windows
  • Activate CLion IDE
  • CLion IDE for C/C++ Development

Back to Top

Links

  • Contact
  • Privacy Policy
  • Cookie Policy

www.TestingDocs.com