Tags

11g (3) 12c (4) 18c (2) 19c (3) ASM (3) Critical Patch (12) Dataguard (10) GRID (3) GitLab (2) Linux (11) OEM (2) ORA Errors (16) Oracle (20) RMAN (5)

Friday, December 5, 2025

Oracle JDBC Connection Test



How to test Oracle connection via JDBC Thin driver.



PURPOSE: All documents are provided on this Blog just for educational purposes only.  Please make sure that you run it in your test environment before to move on to production environment. 


STEP 1.
Create a file OracleCon.java with the following code.
vi OracleCon.java

import java.sql.*;
public class OracleCon
{
public static void main(String args[])
  {
   Class.forName("oracle.jdbc.driver.OracleDriver");
     String url = "jdbc:oracle:thin:@ ORADBPRD.th.com:1521:KARDBPRD";
       Connection conn =
         DriverManager.getConnection(url,"user_tst01","pw_xyz");
         conn.setAutoCommit(false);
     Statement stmt = conn.createStatement();
     ResultSet rs=stmt.executeQuery("select user from dual;");
     while(rs.next())
     {
      System.out.println (rs.getString(1));
     }
   stmt.close();
   System.out.println ("Connection succeeded");
  }
}

STEP 2.
Compile the code.


Execute the program as follow.

Connection succeeded




No comments:

Post a Comment

How to create swap file

  How to Create, Verify, and Increase Swap Space on Linux Swap space is disk space that Linux uses as virtual memory when physical RAM is e...