/* * Created on 6/10/2003 * * Used to provide a connection factory for a particular database * server. */ import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; /** * @author bsutton * * To change the template for this generated type comment go to * Window>Preferences>Java>Code Generation>Code and Comments */ public class DBServer { public static String MSSQL = "com.microsoft.jdbc.sqlserver.SQLServerDriver"; // Just a sample string for MSSQL. public static String MSURL = "jdbc:microsoft:sqlserver://server:1433;DatabaseName=abc;user=fred;password=nerk"; static Connection factory(String strJDBCDriver, String strJDBCURL) throws SQLException { if (strJDBCDriver == null) throw new IllegalArgumentException("JDBCDriver must have a value."); if (strJDBCURL == null) throw new IllegalArgumentException("strJDBCURL must have a value."); Connection conn = null; try { // First, lets make sure the JDBC Driver is installed on this system. Class.forName(strJDBCDriver); // Now let's attempt to get a connection using the DriverManager... conn = DriverManager.getConnection(strJDBCURL); } catch (ClassNotFoundException ex) { System.out.println(ex); throw new SQLException("The selected JDBC Driver " + strJDBCDriver + " is not on the class path."); } catch (NoClassDefFoundError ex) { System.out.println(ex); throw new SQLException("The selected JDBC Driver " + strJDBCDriver + " is not installed correctly."); } return conn; } public static void main(String[] args) { } }