1 16 package org.apache.juddi.datastore.jdbc; 17 18 import java.sql.Connection ; 19 import java.sql.DriverManager ; 20 import java.sql.SQLException ; 21 22 import org.apache.commons.logging.Log; 23 import org.apache.commons.logging.LogFactory; 24 25 26 29 public class Database 30 { 31 private static Log log = LogFactory.getLog(Database.class); 33 34 private static final String JDBC_DRIVER_KEY = "juddi.jdbcDriver"; 35 private static final String DEFAULT_JDBC_DRIVER = "com.mysql.jdbc.Driver"; 36 37 private static final String JDBC_URL_KEY = "juddi.jdbcURL"; 38 private static final String DEFAULT_JDBC_URL = "jdbc:mysql://localhost/juddi"; 39 40 private static final String JDBC_USERNAME_KEY = "juddi.jdbcUser"; 41 private static final String DEFAULT_JDBC_USERNAME = "juddi"; 42 43 private static final String JDBC_PASSWORD_KEY = "juddi.jdbcPassword"; 44 private static final String DEFAULT_JDBC_PASSWORD = "juddi"; 45 46 49 public static Connection aquireConnection() 50 throws SQLException 51 { 52 55 String jdbcDriver = System.getProperty(JDBC_DRIVER_KEY,DEFAULT_JDBC_DRIVER); 56 String jdbcURL = System.getProperty(JDBC_URL_KEY,DEFAULT_JDBC_URL); 57 String jdbcUser = System.getProperty(JDBC_USERNAME_KEY,DEFAULT_JDBC_USERNAME); 58 String jdbcPassword = System.getProperty(JDBC_PASSWORD_KEY,DEFAULT_JDBC_PASSWORD); 59 60 62 try { 63 Class.forName(jdbcDriver); 64 } 65 catch(ClassNotFoundException cnfex) { 66 throw new SQLException ("Could not locate JDBC Driver '" + 67 jdbcDriver+"' in classpath: "+cnfex.getMessage()); 68 } 69 70 72 Connection connection = 73 DriverManager.getConnection(jdbcURL,jdbcUser,jdbcPassword); 74 75 return connection; 76 } 77 } 78 | Popular Tags |