Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.*;
- class ConnTest {
- public static void main (String[] args) throws Exception
- {
- System.out.println ("*****************************************************************************");
- System.out.println ("* Testing ORACLE jdbc connectivity - by Julian Gyurov *");
- System.out.println ("*****************************************************************************");
- System.out.println ("* Loading driver ORACLE jdbc Oracle Driver *");
- System.out.println ("* from folder \\...\\lib\\ext\\ojdbc6.jar *");
- Class.forName ("oracle.jdbc.OracleDriver");
- System.out.println ("* *");
- System.out.println ("* Driver loaded OK *");
- System.out.println ("*****************************************************************************");
- System.out.println ("");
- /*
- String machineName = "mymach.myhost.my";
- String port = "1521";
- String service = "test";
- String user = "sys as sysdba";
- String pass = "mypass";
- */
- String machineName = "";
- String port = "";
- String service = "";
- String user = "";
- String pass = "";
- //Machine Name
- System.out.println("machineName [mymach.myhost.my]: ");
- java.util.Scanner scanner = new java.util.Scanner(System.in);
- machineName = scanner.nextLine();
- if( machineName.isEmpty() ){machineName="mymach.myhost.my";}
- //System.out.println("Your machiName: " + machineName);
- //Port
- System.out.println("Port [1521]: ");
- port = scanner.nextLine();
- if( port.isEmpty() ){port="1521";}
- //Service
- System.out.println("Service [test]: ");
- service = scanner.nextLine();
- if( service.isEmpty() ){service="test";}
- //User
- System.out.println("User [sys as sysdba]: ");
- user = scanner.nextLine();
- if( user.isEmpty() ){user="sys as sysdba";}
- //Pass
- System.out.println("Pass [mypass]: ");
- pass = scanner.nextLine();
- if( pass.isEmpty() ){pass="mypass";}
- System.out.println ("");
- System.out.println ("machineName="+machineName);
- System.out.println ("");
- System.out.println ("port="+port);
- System.out.println ("");
- System.out.println ("service="+service);
- System.out.println ("");
- System.out.println ("user="+user);
- System.out.println ("");
- System.out.println ("pass="+pass);
- System.out.println ("");
- //Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@//mymach.myhost.my:1521/test","sys as sysdba","mypass");
- //("jdbc:oracle:thin:@//localhost:1521/orcl", "scott", "tiger");
- // @//machineName:port/SID, userid, password
- Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@//"+
- machineName+
- ":"+port+
- "/"+service,
- user,
- pass);
- //("jdbc:oracle:thin:@//localhost:1521/orcl", "scott", "tiger");
- // @//machineName:port/SID, userid, password
- try {
- Statement stmt1 = conn.createStatement();
- Statement stmt2 = conn.createStatement();
- try {
- ResultSet rset1 = stmt1.executeQuery("select DBID from v$database");
- ResultSet rset2 = stmt2.executeQuery("select BANNER from SYS.V_$VERSION");
- try {
- System.out.println ("ORACLE VERSION:");
- while (rset2.next())
- System.out.println (rset2.getString(1)); // Print col 1
- System.out.println ("");
- }
- finally {
- try { rset2.close(); } catch (Exception ignore) {}
- }
- try {
- System.out.println ("ORACLE DBID:");
- while (rset1.next())
- System.out.println (rset1.getString(1)); // Print col 1
- System.out.println ("");
- }
- finally {
- try { rset1.close(); } catch (Exception ignore) {}
- }
- }
- finally {
- try { stmt1.close(); stmt2.close(); } catch (Exception ignore) {}
- }
- }
- finally {
- try { conn.close(); } catch (Exception ignore) {}
- }
- System.out.println ("*****************************************************************************");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement