/******************************************** * * Main.java shows how to use ConnectDB class * to connect to Oracle / MySQL databses * * kishan@hackorama.com 2000 www.hackorama.com * ********************************************/ import java.io.*; import java.sql.*; import ConnectDB.*; public class Main { public static void main( String[] args) { Main start = new Main(); } public Main() { /* * Example of connecting to ORACLE ( with error messages OFF ) */ System.out.println( "Connecting to Oracle Server \n"); ConnectDB connect = new ConnectDB("127.0.0.1", /* IP */ "1521" , /* port */ "orcl" , /* sid */ "scott" , /* user */ "tiger" , /* pass */ "ORACLE" , /* type */ false ); /* error messages */ if( connect.ifConnected() ) { testSQL( connect ); connect.disConnect(); } else { System.out.println( "FAILED Connecting to Oracle Server \n"); } /* * Example of connecting to MySQL ( with error messages ON ) */ System.out.println( "Connecting to MySQL Server \n"); connect = new ConnectDB( "127.0.0.1" , "3306" , "matrix" , "neo" , "redpill" , "MYSQL", true ); if( connect.ifConnected() ) { testSQL( connect ); connect.disConnect(); } else { System.out.println( "FAILED Connecting to MySQL Server \n"); } } void testSQL( ConnectDB connect) { try{ if( connect.ORACLE() ) connect.rs = connect.stmt.executeQuery("SELECT USER FROM DUAL"); else if ( connect.MYSQL() ) connect.rs = connect.stmt.executeQuery("SELECT USER()"); while( connect.rs.next() ){ System.out.println( "USER IS : " +connect.rs.getString(1) +"\n" ); } connect.rs.close(); }catch( Exception e){ connect.printEx(e); } } }