source: trunk/gsdl3/packages/gsdl-as/src/org/greenstone/gsdlas/database/DatabaseManager.java@ 8888

Last change on this file since 8888 was 8888, checked in by schweer, 19 years ago

notifications

  • Property svn:keywords set to Author Date Id Revision
File size: 1.6 KB
Line 
1/*
2 * Created on Dec 1, 2004
3 * Copyright (C) Andrea Schweer, 2004
4 *
5 * This file is part of the Greenstone Alerting Service.
6 * Refer to the COPYING file in the base directory of this package
7 * for licensing information.
8 */
9package org.greenstone.gsdlas.database;
10
11import java.sql.*;
12import java.sql.Connection;
13import java.sql.DriverManager;
14
15
16/**
17 * @author andrea
18 *
19 * TODO To change the template for this generated type comment go to
20 * Window - Preferences - Java - Code Style - Code Templates
21 */
22public class DatabaseManager {
23
24 private static DatabaseManager instance;
25 private Connection database;
26
27 private DatabaseManager() {
28 // hide constructor
29 }
30
31 public static DatabaseManager getInstance() {
32 if (instance == null) {
33 instance = new DatabaseManager();
34 }
35 return instance;
36 }
37
38 public Connection getDatabaseConnection() throws DatabaseException {
39 if(database == null) {
40 String connectionString = "jdbc:mysql://localhost/alerting?user=gsdl3admin";
41 try {
42 Class.forName("com.mysql.jdbc.Driver").newInstance();
43 database = DriverManager.getConnection(connectionString);
44 } catch (Exception e) {
45 if (e instanceof SQLException) {
46 SQLException sqle = (SQLException) e;
47 System.err.println("SQLState: " + sqle.getSQLState());
48 }
49 throw new DatabaseException("Could not establish connection to database (" + connectionString + ")", e);
50 }
51 }
52 return database;
53 }
54
55
56}
Note: See TracBrowser for help on using the repository browser.