import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class TestConnection{
public static void main(String args[]) {
Connection connection = null;
try { // load driver
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("Loading the driver...");
}
catch( Exception e ) { //problem load driver,class not exist
e.printStackTrace( );
return;
}
try {
String dbURL = "jdbc:odbc:NorthwindDSN";
System.out.println("Establishing connection...");
connection =
DriverManager.getConnection(dbURL,"","");
System.out.println("Connect to " + connection.getCatalog() + " successfully!");
// Do whatever queries or updates you want here!!!
}
catch( SQLException e ) {
e.printStackTrace( );
}
finally {
if( connection != null ) {
try { connection.close( ); }
catch( SQLException e ) {
e.printStackTrace( );
}
}
}
}
}