1 16 17 package org.apache.ws.jaxme.pm.jdbc; 18 19 import java.sql.Connection ; 20 import java.sql.Driver ; 21 import java.sql.DriverManager ; 22 import java.sql.SQLException ; 23 24 import javax.xml.bind.JAXBException; 25 26 import org.apache.ws.jaxme.JMManager; 27 import org.apache.ws.jaxme.pm.impl.PMImpl; 28 import org.apache.ws.jaxme.util.ClassLoader; 29 30 33 public abstract class PMJdbcImpl extends PMImpl { 34 private String driver, url, user, password; 35 36 38 public PMJdbcImpl() { 39 super(); 40 } 41 42 public void init(JMManager pManager) throws JAXBException { 43 super.init(pManager); 44 String myDriver = pManager.getProperty("jdbc.driver"); 45 if (myDriver == null || myDriver.length() == 0) { 46 throw new JAXBException("Missing property: 'jdbc.driver' (JDBC driver class)"); 47 } 48 driver = myDriver; 49 try { 50 ClassLoader.getClass(myDriver, Driver .class); 51 } catch (ClassNotFoundException e) { 52 throw new JAXBException("Unable to load driver class " + myDriver); 53 } 54 String myUrl = pManager.getProperty("jdbc.url"); 55 if (myUrl == null || myUrl.length() == 0) { 56 throw new JAXBException("Missing property: 'jdbc.url' (JDBC database URL)"); 57 } 58 url = myUrl; 59 60 user = pManager.getProperty("jdbc.user"); 61 62 password = pManager.getProperty("jdbc.password"); 63 } 64 65 67 public String getJdbcDriver() { 68 return driver; 69 } 70 71 73 public String getJdbcUrl() { 74 return url; 75 } 76 77 79 public String getJdbcUser() { 80 return user; 81 } 82 83 85 public String getJdbcPassword() { 86 return password; 87 } 88 89 91 public Connection getConnection() throws SQLException { 92 return DriverManager.getConnection(getJdbcUrl(), getJdbcUser(), getJdbcPassword()); 93 } 94 } 95 | Popular Tags |