View Javadoc

1   /*
2    * Copyright 2001-2004 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
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.juddi.registry.RegistryEngine;
23  import org.apache.juddi.util.Config;
24  
25  
26  /***
27   * @author Steve Viens (sviens@apache.org)
28   */
29  public class Database
30  {
31    // grab the JDBC properties we'll need to setup 
32    // the connection pool.
33    private static String jdbcDriver = Config.getStringProperty(
34  		  RegistryEngine.PROPNAME_JDBC_DRIVER,RegistryEngine.DEFAULT_JDBC_DRIVER);
35    private static String jdbcURL = Config.getStringProperty(
36  		  RegistryEngine.PROPNAME_JDBC_URL,RegistryEngine.DEFAULT_JDBC_URL);
37    private static String jdbcUser = Config.getStringProperty(
38  		  RegistryEngine.PROPNAME_JDBC_USERNAME,RegistryEngine.DEFAULT_JDBC_USERNAME);
39    private static String jdbcPassword = Config.getStringProperty(
40  		  RegistryEngine.PROPNAME_JDBC_PASSWORD,RegistryEngine.DEFAULT_JDBC_PASSWORD);
41  
42    /***
43     *
44     */
45    public static Connection aquireConnection()
46      throws SQLException
47    {
48     
49  
50      // make sure the JDBC Driver is loaded
51      
52      try {
53      	Class.forName(jdbcDriver);
54      }
55      catch(ClassNotFoundException cnfex) {
56        throw new SQLException("Could not locate JDBC Driver '" +
57        		jdbcDriver+"' in classpath: "+cnfex.getMessage());
58      }
59  
60      // okay, get and return the connection
61      
62      Connection connection = 
63      	DriverManager.getConnection(jdbcURL,jdbcUser,jdbcPassword);
64      	
65      return connection;
66    }
67  }