Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: Is Database Up?

Re: Is Database Up?

From: David Newman <dnewman_at_maraudingpirates.org>
Date: 28 Aug 2006 13:18:44 -0400
Message-ID: <f6wlkp8ixsb.fsf@BOS004777.na.pxl.int>


"amerar_at_iwc.net" <amerar_at_iwc.net> writes:

> David Newman wrote:
>
> Would be great, but this place does not have DBD/DBI and they do not
> want to install it.....go figure??!?!!?

Well, you could probably install the perl modules in oracle's home directory or install perl entirely under oracle's home dir (or anyplace else oracle has write access)

But when I encounter a system that I don't have Oracle DBD::Oracle but java is available I will go the JDBC route as it's pretty easy to write a simple class to connect to a database and execute a single select statement. This has the advantage of running anywhere java is available because the oracle thin client is implemented entirely in java.

<<<<<DBTest.java>>>>>
package com.example.dbtest;

import java.sql.*;
import javax.sql.*;

class DBTest {
  public static void main( String[] args ) {     // Load the Oracle JDBC Driver
    try {
      Class.forName("oracle.jdbc.driver.OracleDriver");     } catch( Exception e ) {

      System.out.println( "Failed to load oracle.jdbc.driver.OracleDriver" );
      System.out.println( "Make sure ojdbc14.jar is in your CLASSPATH" );
      System.exit( 1 );

    }

    // Make the connection
    String host = "db001";
    String port = "1442";

    String SID = "ORCL";
    String username = "tonytester";
    String password = "yo";

    String jdbcURL = "jdbc:oracle:thin:@" + host + ":" + port + ":" + SID;     Connection con = null;

    try {

      con = DriverManager.getConnection( jdbcURL,
                                         username, password );
      String selectsql = "SELECT status FROM v$instance";
      PreparedStatement stmt = conn.prepareStatement( selectsql );
      ResultSet rs = stmt.executeQuery();
      rs.next();
      String status = rs.getString( 1 );
      if( ! status.equals( "OPEN" ) ) {
        System.exit( 1 );
      }

      rs.close();
      stmt.close();
      con.close();

    } catch ( Exception e ) {
      System.out.println( SID + " Database Down", e.getMessage() );
      System.exit( 1 );

    }

  }
} Received on Mon Aug 28 2006 - 12:18:44 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US