package examples.jdbc.oracle;

import java.sql.*;
import java.util.Properties;

/**
 * This simple example shows the alternatives for making a
 * JDBC connection to an Oracle instance.
 * <p>
 * This example is run on the command line and is output to
 * System.out.
 *<h3>To set up this example:</h3>
 *<ol>
 *<li>Set up your development shell as described in <a
 *href=../../../techstart/environment.html>Setting up your environment</a>.
 *<p>
 *<li> Change connection parameters to correspond to your Oracle configuration.
 *If you need more help, check the section on connecting
 *to a database in the Developers Guide, <a
 *href=../../../classdocs/API_joci.html>Using WebLogic jDriver for Oracle</a>.
 *
 *<p>
 *
 *<li>Compile this example by executing the following command in your development shell:
 *
 *<p>
 *
 *<font face="Courier New"><b>$ javac -d %CLIENT_CLASSES% login.java</b></font>
 *<p>	
 *
 *<li>Run this example by executing the following command in your development shell:
 *
 *<p>
 *
 *<font face="Courier New"><b>$ java examples.jdbc.oracle.login</b></font>
 *
 *</ol>
 *
 * @author Copyright (c) 1996-2000 by BEA Systems, Inc.  All Rights Reserved.
 */
public class login {

  public static void main(String argv[])
       throws Exception
  {
    
    // You can connect to a database with JDBC in various ways.
    // The first way uses a properties object to pass in the user, password, and server. 
    
    Properties props = new Properties();
    props.put("user",     "scott");
    props.put("password", "tiger");
    props.put("server",   "DEMO");
    
    Driver myDriver = (Driver) Class.forName("weblogic.jdbc.oci.Driver").newInstance();
    Connection conn1 = myDriver.connect("jdbc:weblogic:oracle", props);
    conn1.close();
    System.out.println("Logged in successfully with style #1.");
    
    // The simplest thing to do is to embed the server name in the URL.
    // Then use a Properties object to pass in the username and password.
    Properties props2 = new Properties();
    props2.put("user",     "scott");
    props2.put("password", "tiger");

    Connection conn2 = myDriver.connect("jdbc:weblogic:oracle:DEMO", props2);
    conn2.close();
    
    System.out.println("Logged in successfully with style #2.");
  }
}

