How to Connect Oracle 19c Database in WebLogic Docker Using JSP
Learn how to connect an Oracle 19c Database to a WebLogic Docker container using JSP. This guide covers setting up your environment, creating a JSP Hello World, configuring database connections, and deploying the WAR file to WebLogic for dynamic database interaction.
Tutorial Steps
Download Tutorial

Step 1 – Download Oracle JDBC Driver
To connect to an Oracle database from a JSP page, you need to download the latest Oracle JDBC driver. Follow the steps below:
- Go to the Oracle JDBC Downloads page.
- Download the latest
ojdbc11.jar
file. - Accept the license agreement to start the download.
Step 2 – Set Up Your Development Environment
For this tutorial, we'll use IntelliJ IDEA to create and run a JSP project:
- Open IntelliJ IDEA and create a new project.
- Select
Java
and then choose theWeb Application
template. - Click
Next
to proceed to the next page. - Under
Dependencies
, go to theSpecifications
section and selectFull Platform
. ClickNext
. - Choose a suitable name and location for your project and click
Finish
. - After the project is created, go to the
Edit Configurations
in the top menu. - Click the
+
icon to add a new configuration and selectTomcat Server > Local
. - In the
Tomcat Server
configuration window, click onConfigure
to set up a new Tomcat server installation directory if not already configured. - Under the
Deployment
tab, click the+
button to add an artifact. - Select the
Artifact
type you want to deploy, usually thewar:exploded
version of your project, and clickOK
. - Click
Apply
and thenOK
to save the configuration.
Step 3 – Create a Simple JSP Hello World
Before implementing the database connection, let's ensure our JSP setup works by creating a simple Hello World page:
- Open
index.jsp
and replace the content with the following code:
<html>
<body>
<h2>Hello World!</h2>
</body>
</html>
- Run your project to ensure everything is set up correctly.
Step 4 – Set Up the Project for Oracle Database Connection
To connect to the Oracle 19c database, follow these steps:
- Create a folder named
lib
inside theWEB-INF
directory of your project. - Copy the downloaded
ojdbc11.jar
file into thislib
folder. - In IntelliJ IDEA, right-click on your project and select
Open Module Settings
. - From
Dependencies
, click the+
button, select1 JARs or Directories..
and add theojdbc11.jar
file from yourWEB-INF/lib
folder. - Click
Apply
and thenOK
.
Step 5 – Implement the JSP Code for Database Connection
Now, let's use the provided JSP code to connect to the Oracle 19c database:
<!DOCTYPE html>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="java.sql.*" %>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Oracle HR Database</title>
<!-- Bootstrap 5 CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.5/font/bootstrap-icons.css" rel="stylesheet">
</head>
<body>
<div class="container mt-5">
<h2 class="text-center mb-4">Data from Oracle HR Database</h2>
<div class="card">
<div class="card-body">
<div class="table-responsive">
<table class="table table-bordered table-hover">
<thead class="table-dark">
<tr>
<th>EMPLOYEE_ID</th>
<th>FIRST_NAME</th>
<th>LAST_NAME</th>
<th>PHONE_NUMBER</th>
<th>HIRE_DATE</th>
<th>SALARY</th>
<th>Details</th>
</tr>
</thead>
<tbody>
<%
// JDBC connection parameters
String url = "jdbc:oracle:thin:@oracle19c/orclpdb1"; // Replace with your database URL. Replace oracle19c with your weblogic docker name or for a remote server, use server ip address .
String username = "hr"; // replace with your username
String password = "hr"; // replace with your password
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try {
// Load Oracle JDBC Driver
Class.forName("oracle.jdbc.driver.OracleDriver");
// Establish connection
conn = DriverManager.getConnection(url, username, password);
// Create a statement
stmt = conn.createStatement();
// Execute a query
String query = "SELECT * FROM EMPLOYEES"; // replace with your table name
rs = stmt.executeQuery(query);
// Process the result set
while (rs.next()) {
int employeeId = rs.getInt("EMPLOYEE_ID");
String firstName = rs.getString("FIRST_NAME");
String lastName = rs.getString("LAST_NAME");
String phoneNumber = rs.getString("PHONE_NUMBER");
Date hireDate = rs.getDate("HIRE_DATE");
double salary = rs.getDouble("SALARY");
out.println("<tr>");
out.println("<td>" + employeeId + "</td>");
out.println("<td>" + firstName + "</td>");
out.println("<td>" + lastName + "</td>");
out.println("<td>" + phoneNumber + "</td>");
out.println("<td>" + hireDate + "</td>");
out.println("<td>$" + salary + "</td>");
out.println("<td><button type='button' class='btn btn-primary' data-bs-toggle='modal' data-bs-target='#detailsModal" + employeeId + "'>");
out.println("<i class='bi bi-info-circle'></i> Details</button></td>");
out.println("</tr>");
// Modal for details
out.println("<div class='modal fade' id='detailsModal" + employeeId + "' tabindex='-1' aria-labelledby='detailsModalLabel" + employeeId + "' aria-hidden='true'>");
out.println("<div class='modal-dialog modal-dialog-centered'>");
out.println("<div class='modal-content'>");
out.println("<div class='modal-header'>");
out.println("<h5 class='modal-title' id='detailsModalLabel" + employeeId + "'>Employee Details</h5>");
out.println("<button type='button' class='btn-close' data-bs-dismiss='modal' aria-label='Close'></button>");
out.println("</div>");
out.println("<div class='modal-body'>");
out.println("<p><strong>Employee ID:</strong> " + employeeId + "</p>");
out.println("<p><strong>First Name:</strong> " + firstName + "</p>");
out.println("<p><strong>Last Name:</strong> " + lastName + "</p>");
out.println("<p><strong>Phone Number:</strong> " + phoneNumber + "</p>");
out.println("<p><strong>Hire Date:</strong> " + hireDate + "</p>");
out.println("<p><strong>Salary:</strong> $" + salary + "</p>");
out.println("</div>");
out.println("<div class='modal-footer'>");
out.println("<button type='button' class='btn btn-secondary' data-bs-dismiss='modal'>Close</button>");
out.println("</div>");
out.println("</div>");
out.println("</div>");
out.println("</div>");
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (rs != null) try { rs.close(); } catch (SQLException e) { e.printStackTrace(); }
if (stmt != null) try { stmt.close(); } catch (SQLException e) { e.printStackTrace(); }
if (conn != null) try { conn.close(); } catch (SQLException e) { e.printStackTrace(); }
}
%>
</tbody>
</table>
</div>
</div>
</div>
</div>
<!-- Bootstrap 5 JS -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>
Step 6 – Connect Oracle 19c and WebLogic to the Same Network
If you are using docker in the same server/network, make sure Oracle 19c and WebLogic are on the same network. The following commands will create a docker network named oracle-network
. Then connect oracle19c
and weblogic
docker to the oracle-network
docker. Use docker names as you have, you can check it with docker ps
command. Execute the following commands in your terminal:
docker network create oracle-network
docker network connect oracle-network oracle19c
docker network connect oracle-network weblogic
Step 7 – Generate WAR File
If you have used Maven, click on the Maven icon from the right side of IntelliJ Idea and expand YourProject
> Lifecycle
and then package
In your project directory, you will find a package
directory containing your required .war
file.
If you have used Gradle, click on the Gradle icon from the right side of IntelliJ Idea and expand YourProject
> Task
> build
and then war
In your project directory, you will find your required .war
file at build
> libs
location.
Step 8 – Deploy the JSP Project to WebLogic
To deploy your project to WebLogic, you can follow our WebLogic Deployment Tutorial.