3 Using Eclipse and IntelliJ

The following sections provide information about how to connect to Oracle Database using Eclipse and IntelliJ IDEs:

3.1 Using the Eclipse IDE

You can establish a connection to Oracle Database using the Eclipse IDE.

3.1.1 Setting Up a Maven Project

This section lists the steps to set up a Maven project.

Make sure to complete all the steps from the Prerequisites section.
  1. Create a Maven project.
    1. From the File menu, select New, and then select Project. You can either use Maven archetype or select Create a simple project (skip archetype selection).
    2. Choose GAV for your Maven project. These will appear in the pom.xml file for the project.
      • Group Id: com.oracle
      • Artifact Id: JDBCquickstart
      • Version: leave it as 0.0.1-SNAPSHOT
  2. Create the QuickStart.java file.
    1. Right-click on src/main/java, select New, and then select Class.
    2. Enter the following values, and then click Finish.
      • Package: com.oracle.jdbctest
      • Name: QuickStart

        Note:

        Make sure to copy the contents of the QuickStart.java file to this new file created.
  3. Modify the pom.xml file with the following changes:
    Add Oracle JDBC driver as a dependency.

    Note:

    ojdbc8-production will download Oracle JDBC driver (ojdbc8.jar) along with ucp.jar (it is a JAR file required for using UCP as a client side connection pool). Refer to the Maven Central Guide for more details.
    <properties>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
    </properties>
    <dependencies>
      <dependency>
        <groupId>com.oracle.database.jdbc</groupId>
        <artifactId>ojdbc8-production</artifactId>
        <version>21.1.0.0</version>
        <type>pom</type>
      </dependency>
    </dependencies>

3.1.2 Building and Running a Sample Java Program

This section lists the steps to build and run a Java program.

Make sure you do not have any compilation error in the Java code and you are using the latest JDK version in Eclipse. Also, make sure that Oracle Database is running on Docker.
  1. Right-click QuickStart.java.
  2. Click Run As, and then click Java Application to run the sample Java program.
Sample Output:

You will see the queried rows returned from the new table todoitem and a message Congratulations! You have successfully used Oracle Database as shown in the following screen:
Sample Output

3.2 Using the IntelliJ IDE

You can establish a connection to Oracle Database using the IntelliJ IDE.

3.2.1 Setting Up a Maven Project

This section lists the steps to set up a Maven project.

Make sure to complete all the steps from the Prerequisites section.
  1. Create a Maven project.
    1. From the File menu, select New, and then select Project.
    2. Choose Maven on the left side and choose the latest version of JDK as Project SDK. You can use any Maven archetype or add your own.
    3. Click Next.
    4. Give Name as Quickstart.
  2. Create QuickStart.java file.
    1. Right-click on src/main/java.
    2. Select New, and then select Java Class.
    3. Enter com.oracle.jdbctest.QuickStart.java. This will create the required package structure as well. Make sure to copy contents of QuickStart.java file to this new file.
  3. Modify the pom.xml file with the following changes:
    Add Oracle JDBC driver as a dependency.

    Note:

    ojdbc8-production will download the Oracle JDBC driver (ojdbc8.jar) along with ucp.jar (it is a JAR file required for using UCP as a client side connection pool). Refer to the Maven Central Guide for more details.
    <properties>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
    </properties>
    <dependencies>
      <dependency>
        <groupId>com.oracle.database.jdbc</groupId>
        <artifactId>ojdbc8-production</artifactId>
        <version>21.1.0.0</version>
        <type>pom</type>
      </dependency>
    </dependencies>

3.2.2 Building and Running QuickStart

This section lists the steps to build and run QuickStart.

  1. Compile the Java code.

    Right-click QuickStart.java, and then click Build Module 'QuickStart'.

    Make sure that there are no compilation errors. Also, ensure that Oracle Database is running on Docker and is accessible.

  2. Run the sample Java program.

    Right-click QuickStart.java, and then click Run 'QuickStart.main()'.

Sample Output:

You will see the queried rows returned from the database and a message Congratulations! You have successfully used Oracle Database as shown in the following screen:


Sample Output