get Driver class name for each JDBC driver - Java java.sql

Java examples for java.sql:Driver

Description

get Driver class name for each JDBC driver

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        String db = "java2s.com";
        System.out.println(getDriver(db));
    }//from  w w  w.  j  av  a 2 s  .  c o  m

    private static final String driverDB2 = "COM.ibm.db2.jdbc.app.DB2Driver";
    private static final String driverJdbcOdbc = "sun.jdbc.odbc.JdbcOdbcDriver";
    private static final String driverMsSQLServer = "weblogic.jdbc.mssqlserver4.Driver";
    private static final String driverMsSQLServerJTurbo = "com.ashna.jturbo.driver.Driver";
    private static final String driverMsSQLServerSprinta = "com.inet.tds.TdsDriver";
    private static final String driverMsSQLServer2000 = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
    private static final String driverMySQL = "org.gjt.mm.mysql.Driver";
    private static final String driverOracle8i = "oracle.jdbc.driver.OracleDriver";
    private static final String driverOracle9i = "oracle.jdbc.driver.OracleDriver";
    private static final String driverOracleThin = "oracle.jdbc.driver.OracleDriver";
    private static final String driverPointBase = "com.pointbase.jdbc.jdbcUniversalDriver";
    private static final String driverCloudscape = "COM.cloudscape.core.JDBCDriver";
    private static final String driverCloudscapeRmi = "RmiJdbc.RJDriver";
    private static final String driverFirebird = "org.firebirdsql.jdbc.FBDriver";
    private static final String driverIdsServer = "ids.sql.IDSDriver";
    private static final String driverInformixDynamic = "com.informix.jdbc.IfxDriver";
    private static final String driverInstantDB_v3_13 = "jdbc.idbDriver";
    private static final String driverInstantDB_v3_14 = "org.enhydra.instantdb.jdbc.idbDriver";
    private static final String driverInterbase = "interbase.interclient.Driver";
    private static final String driverHypersonicSQL_v1_2 = "hSql.hDriver";
    private static final String driverHypersonicSQL_v1_3 = "org.hsql.jdbcDriver";
    private static final String driverPostgreSQL_v6_5 = "postgresql.Driver";
    private static final String driverPostgreSQL_v7 = "org.postgresql.Driver";
    private static final String driverSysbase_v4_2 = "com.sybase.jdbc.SybDriver";
    private static final String driverSysbase_v5_2 = "com.sybase.jdbc2.jdbc.SybDriver";

    private static String getDriver(String db) {
        switch (db.toUpperCase()) {
        case "CLOUDSCAPE":
            return driverCloudscape;
        case "CLOUDSCAPE_RMI":
            return driverCloudscapeRmi;
        case "DB2":
            return driverDB2;
        case "FIREBIRD":
            return driverFirebird;
        case "HYPERSONIC_v1_2":
            return driverHypersonicSQL_v1_2;
        case "HYPERSONIC_v1_3":
            return driverHypersonicSQL_v1_3;
        case "IDSSERVER":
            return driverIdsServer;
        case "INFORMIX":
            return driverInformixDynamic;
        case "INSTANTDB_V3_13":
            return driverInstantDB_v3_13;
        case "INSTANTDB_V3_14":
            return driverInstantDB_v3_14;
        case "INTERBASE":
            return driverInterbase;
        case "JDBCODBC":
            return driverJdbcOdbc;
        case "MSSQLSERVER":
            return driverMsSQLServer;
        case "MSSQLSERVER2000":
            return driverMsSQLServer2000;
        case "MSSQLSERVERJTURBO":
            return driverMsSQLServerJTurbo;
        case "MSSQLSERVERSPRINTA":
            return driverMsSQLServerSprinta;
        case "MYSQL":
            return driverMySQL;
        case "ORACLE8I":
            return driverOracle8i;
        case "ORACLE9I":
            return driverOracle9i;
        case "ORACLETHINSID":
        case "ORACLETHINSERVICE":
            return driverOracleThin;
        case "POINTBASE":
            return driverPointBase;
        case "POSTGRESQL_V6_5":
            return driverPostgreSQL_v6_5;
        case "POSTGRESQL_V7":
            return driverPostgreSQL_v7;
        case "SYSBASE_V4_2":
            return driverSysbase_v4_2;
        case "SYSBASE_V5_2":
            return driverSysbase_v5_2;
        default:
            return null;
        }
    }
}

Related Tutorials