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
|
Rev | Line | |
---|
[8717] | 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 | */
|
---|
| 9 | package org.greenstone.gsdlas.database;
|
---|
| 10 |
|
---|
[8888] | 11 | import java.sql.*;
|
---|
[8717] | 12 | import java.sql.Connection;
|
---|
| 13 | import 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 | */
|
---|
| 22 | public 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) {
|
---|
[8738] | 40 | String connectionString = "jdbc:mysql://localhost/alerting?user=gsdl3admin";
|
---|
[8717] | 41 | try {
|
---|
| 42 | Class.forName("com.mysql.jdbc.Driver").newInstance();
|
---|
[8738] | 43 | database = DriverManager.getConnection(connectionString);
|
---|
[8717] | 44 | } catch (Exception e) {
|
---|
[8888] | 45 | if (e instanceof SQLException) {
|
---|
| 46 | SQLException sqle = (SQLException) e;
|
---|
| 47 | System.err.println("SQLState: " + sqle.getSQLState());
|
---|
| 48 | }
|
---|
[8717] | 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.