Soham_K

TestConnection.java

Nov 1st, 2020 (edited)
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.04 KB | None | 0 0
  1. import java.sql.*;
  2.  
  3. public class TestConnection {
  4.     public static void main(String args[]) {
  5.         String url = "jdbc:oracle:thin:@localhost:1521:orcl";
  6.  
  7.         try {
  8.             Class.forName("oracle.jdbc.driver.OracleDriver");
  9.             System.out.println("Driver Loaded");
  10.             Connection con = DriverManager.getConnection(url, "cricbuzz", "cse216");
  11.             System.out.println("Connection established");
  12.             //Do all work related to this connection;
  13.             Statement statement = con.createStatement();
  14.             ResultSet rs = statement.executeQuery("select * from out_type");
  15.  
  16.             while(rs.next()) {
  17.                 System.out.println(rs.getInt("out_id"));
  18.                 System.out.println(rs.getString("out_title"));
  19.             }
  20.  
  21.             con.close();
  22.         }
  23.         catch (ClassNotFoundException e) {
  24.             System.out.println("Driver not loaded");
  25.         }
  26.         catch (SQLException e) {
  27.             System.out.println("Connection not established");
  28.         }
  29.     }
  30. }
  31.  
Add Comment
Please, Sign In to add comment