KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > juddi > datastore > jdbc > Database


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 JavaDoc;
19 import java.sql.DriverManager JavaDoc;
20 import java.sql.SQLException JavaDoc;
21
22 import org.apache.commons.logging.Log;
23 import org.apache.commons.logging.LogFactory;
24
25
26 /**
27  * @author Steve Viens (sviens@apache.org)
28  */

29 public class Database
30 {
31   // private reference to the jUDDI logger
32
private static Log log = LogFactory.getLog(Database.class);
33
34   private static final String JavaDoc JDBC_DRIVER_KEY = "juddi.jdbcDriver";
35   private static final String JavaDoc DEFAULT_JDBC_DRIVER = "com.mysql.jdbc.Driver";
36
37   private static final String JavaDoc JDBC_URL_KEY = "juddi.jdbcURL";
38   private static final String JavaDoc DEFAULT_JDBC_URL = "jdbc:mysql://localhost/juddi";
39
40   private static final String JavaDoc JDBC_USERNAME_KEY = "juddi.jdbcUser";
41   private static final String JavaDoc DEFAULT_JDBC_USERNAME = "juddi";
42
43   private static final String JavaDoc JDBC_PASSWORD_KEY = "juddi.jdbcPassword";
44   private static final String JavaDoc DEFAULT_JDBC_PASSWORD = "juddi";
45
46   /**
47    *
48    */

49   public static Connection JavaDoc aquireConnection()
50     throws SQLException JavaDoc
51   {
52     // grab the JDBC properties we'll need to setup
53
// the connection pool.
54

55     String JavaDoc jdbcDriver = System.getProperty(JDBC_DRIVER_KEY,DEFAULT_JDBC_DRIVER);
56     String JavaDoc jdbcURL = System.getProperty(JDBC_URL_KEY,DEFAULT_JDBC_URL);
57     String JavaDoc jdbcUser = System.getProperty(JDBC_USERNAME_KEY,DEFAULT_JDBC_USERNAME);
58     String JavaDoc jdbcPassword = System.getProperty(JDBC_PASSWORD_KEY,DEFAULT_JDBC_PASSWORD);
59
60     // make sure the JDBC Driver is loaded
61

62     try {
63         Class.forName(jdbcDriver);
64     }
65     catch(ClassNotFoundException JavaDoc cnfex) {
66       throw new SQLException JavaDoc("Could not locate JDBC Driver '" +
67             jdbcDriver+"' in classpath: "+cnfex.getMessage());
68     }
69
70     // okay, get and return the connection
71

72     Connection JavaDoc connection =
73         DriverManager.getConnection(jdbcURL,jdbcUser,jdbcPassword);
74         
75     return connection;
76   }
77 }
78
Popular Tags