FileDocCategorySizeDatePackage
JdbcCheckup.javaAPI DocExample2136Wed Sep 17 13:50:16 BST 1997None

JdbcCheckup

public class JdbcCheckup extends Object

Fields Summary
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] args)

    // Load the Oracle JDBC driver
    DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());

    // Prompt the user for connect information
    System.out.println ("Please enter information to test connection to the database");
    String user;
    String password;
    String database;

    user = readEntry ("user: ");
    int slash_index = user.indexOf ('/");
    if (slash_index != -1)
    {
      password = user.substring (slash_index + 1);
      user = user.substring (0, slash_index);
    }
    else
      password = readEntry ("password: ");
    database = readEntry ("database (a TNSNAME entry): ");

    System.out.print ("Connecting to the database...");
    System.out.flush ();

    System.out.println ("Connecting...");
    Connection conn =
      DriverManager.getConnection ("jdbc:oracle:oci7:@" + database,
				   user, password);

    System.out.println ("connected.");

    // Create a statement
    Statement stmt = conn.createStatement ();

    // Do the SQL "Hello World" thing
    ResultSet rset = stmt.executeQuery ("select 'Hello World' from dual");

    while (rset.next ())
      System.out.println (rset.getString (1));

    System.out.println ("Your JDBC installation is correct.");
  
static java.lang.StringreadEntry(java.lang.String prompt)

    try
    {
      StringBuffer buffer = new StringBuffer ();
      System.out.print (prompt);
      System.out.flush ();
      int c = System.in.read ();
      while (c != '\n" && c != -1)
      {
	buffer.append ((char)c);
	c = System.in.read ();
      }
      return buffer.toString ().trim ();
    }
    catch (IOException e)
    {
      return "";
    }