package com.mindprod.example;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import static java.lang.System.*;
/**
* demonstrate the how to connect to an Oracle Database with JDBC.
*
* @author Roedy Green, Canadian Mind Products
* @version 1.0 2007-09-17
* @since 2007-09-17
*/
public class ConnectJDBCOracle
{
/**
* which database
*/
private static final String DATABASENAME = "squirrels";
/**
* class name of the JDBC driver
*/
private static final String DRIVERCLASSNAME = "oracle.jdbc.driver.OracleDriver";
/**
* access PASSWORD
*/
private static final String PASSWORD = "sesame";
/**
* login name of user
*/
private static final String USERNAME = "charlie";
/**
* The connection. Handle to the database
*/
private static Connection conn;
/**
* connect to the database
*/
private static Connection connect() throws SQLException
{
try
{
Class.forName( DRIVERCLASSNAME );
}
catch ( Exception e )
{
err.println( "can't load Oracle driver: " + e.getMessage() );
}
return DriverManager.getConnection( "jdbc:oracle:thin:@some.server.name:someportnumber:" + DATABASENAME,
USERNAME,
PASSWORD );
}
/**
* initialise the database
*
* @param args not used
*/
public static void main( String[] args ) throws SQLException
{
conn = connect();
conn.close();
}
}