1 19 20 package org.netbeans.modules.db.sql.execute.ui.util; 21 22 23 24 import java.io.File ; 25 import java.net.URL ; 26 import java.net.URLClassLoader ; 27 import java.sql.Connection ; 28 import java.sql.Driver ; 29 import java.sql.DriverManager ; 30 import java.util.*; 31 import org.netbeans.junit.Manager; 32 33 37 38 39 public class DbUtil { 40 41 public static String DRIVER_CLASS_NAME="driver_class_name"; 42 public static String URL="url"; 43 public static String USER="user"; 44 public static String PASSWORD="password"; 45 46 public static Connection createConnection(Properties p,File [] f) throws Exception { 47 String driver_name=p.getProperty(DRIVER_CLASS_NAME); 48 String url=p.getProperty(URL); 49 String user=p.getProperty(USER); 50 String passwd=p.getProperty(PASSWORD); 51 ArrayList list=new java.util.ArrayList (); 52 for(int i=0;i<f.length;i++){ 53 list.add(f[i].toURI().toURL()); 54 } 55 URL [] driverURLs=(URL [])list.toArray(new URL [0]); 56 URLClassLoader l = new URLClassLoader (driverURLs); 57 Class c = Class.forName(driver_name, true, l); 58 Driver driver=(Driver )c.newInstance(); 59 Connection con=driver.connect(url,p); 60 return con; 61 } 62 63 64 65 66 } 67 68 | Popular Tags |