Monday 25 May 2020

JDBC Connectivity Testing in Linux command Line

Pre-req:
1. Download ojdbc8.jar from oracle website.
2. Compatability of Java, Database, JDBC are in below note id
    Starting With Oracle JDBC Drivers - Installation, Certification, and More! (Doc ID 401934.1)

Step-1:

Create the java file JDBCConnectivity.java as below code

import java.sql.*;
 class JDBCConnectivity{
     public static void main(String args[]) throws SQLException {
         Connection con = null;
         try{
             Class.forName("oracle.jdbc.driver.OracleDriver");
             String DatabaseURL = "jdbc:oracle:thin:@//<Hostname/Database IP Address>:<Port Number>/<Database Service Name>";
             System.out.println("jdbcurl=" + DatabaseURL);
             String UserName = "<Username>";
             String UsrPassword = "<Password>";
             con=DriverManager.getConnection(DatabaseURL,UserName,UsrPassword);
             System.out.println("Connected to the database Successfull.");
             Statement stmt=con.createStatement();
             System.out.println("Executing query");
             ResultSet rs=stmt.executeQuery("SELECT 1 FROM DUAL");
             while(rs.next())
                 System.out.println(rs.getInt("1"));
             con.close();
         }catch(Exception e){ System.out.println(e);}
         finally {
             con.close();
         }
 }
 }

Step-2:
Compile the java code

javac JDBCConnectivity.java

Step-3:

Run the java code using below command

java -Djava.security.egd=file:/dev/../dev/urandom -cp ojdbc8.jar:. JDBCConnectivity

No comments:

Post a Comment

Oracle : Database Startup Time

 Oracle Instance Startup Time SET LINES 2000 SET PAGES 9999 COLUMN INSTANCE_NAME FOR A20 SELECT     instance_name,     to_char(startup_time,...