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 Hypersonic SQL database via JDBC and the client driver.
*
* @author Roedy Green, Canadian Mind Products
* @version 1.0 2011-02-22 initial version
* @since 2011-02-22
*/
public class ConnectJDBCHypersonic
{
/**
* which database
*/
private static final String DATABASENAME = "SQUIRRELS";
/**
* class name of the JDBC driver. Must be accessible on the classpath.
* Mac OS may be missing the Derby driver in the JDK distribution.
* Use the one that comes with NetBeans.
* /Applications/NetBeans/glassfish-v2.1/javadb/lib
*/
private static final String DRIVERCLASSNAME = "org.hsqldb.jdbcDriver";
/**
* 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 Hypersonic database
*
* @return Connection to the database
* @throws java.sql.SQLException
*/
private static Connection connect() throws SQLException
{
try
{
Class.forName( DRIVERCLASSNAME );
}
catch ( Exception e )
{
err.println( "can't load Hypersonic Client JDBC driver: " + e.getMessage() );
}
return DriverManager.getConnection( "jdbc:hsqldb:hsql://aserver.com/" + DATABASENAME, USERNAME, PASSWORD );
}
/**
* initialise the database
*
* @param args not used
*
* @throws java.sql.SQLException
*/
public static void main( String[] args ) throws SQLException
{
conn = connect();
conn.close();
}
}