1 23 import org.objectweb.medor.api.MedorException; 24 25 import java.sql.Connection ; 26 import java.sql.DriverManager ; 27 import java.sql.SQLException ; 28 29 36 37 41 public class JDBCConnection { 42 public Connection getConnection(String dbURL, String driver) throws MedorException { 43 try { 44 System.out.print("Loading driver: " + driver + "..."); 46 Class.forName(driver).newInstance(); 47 System.out.println("success"); 48 } catch (Exception e) { 49 System.out.println("failed. Error: " + e); 50 } 51 System.out.println("Connecting to " + dbURL); 53 try { 54 return DriverManager.getConnection(dbURL); 55 } catch (SQLException sqlexp) { 56 throw new MedorException(sqlexp.getMessage()); 57 } 58 } 59 } 60 | Popular Tags |