1 19 20 package org.netbeans.test.db.util; 21 22 import java.io.File ; 23 import java.net.MalformedURLException ; 24 import java.net.URL ; 25 import java.sql.Connection ; 26 import java.sql.Driver ; 27 import java.util.Properties ; 28 import org.netbeans.modules.derby.DbURLClassLoader; 29 30 34 public class DbUtil { 35 public static final String DRIVER_CLASS_NAME = "org.apache.derby.jdbc.ClientDriver"; 36 private String location; 37 38 public DbUtil(String location){ 39 this.location=location; 40 } 41 42 private File getDerbyFile(String relPath) { 43 return new File (location, relPath); 44 } 45 46 private URL [] getDerbyNetDriverURLs() throws MalformedURLException { 47 URL [] driverURLs = new URL [1]; 48 driverURLs[0] = getDerbyFile("lib/derbyclient.jar").toURI().toURL(); 49 return driverURLs; 50 } 51 52 private Driver getDerbyNetDriver() throws Exception { 53 URL [] driverURLs = getDerbyNetDriverURLs(); 54 DbURLClassLoader l = new DbURLClassLoader(driverURLs); 55 Class c = Class.forName(DRIVER_CLASS_NAME, true, l); 56 return (Driver )c.newInstance(); 57 } 58 59 public Connection createConnection(String url) throws Exception { 60 Driver driver=getDerbyNetDriver(); 61 Properties p=new Properties (); 62 Connection con=driver.connect(url,new Properties ()); 63 return con; 64 } 65 66 } 67 | Popular Tags |