summaryrefslogtreecommitdiffstats
path: root/org/madore/damlengine/WeblogDatabaseConnection.java
blob: c88f5a8450dec2df3c091b14712d5788466ecb45 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package org.madore.damlengine;

import java.util.Properties;
import java.sql.Connection;
import java.sql.SQLException;
import org.postgresql.Driver;

public final class WeblogDatabaseConnection {

    private WeblogDatabaseConnection() { // Forbid instantiation
	throw new AssertionError("WeblogDatabaseConnection cannot be instantiated");
    }

    public static Connection conn;

    public static Connection getConnection()
        throws SQLException {
	if ( conn == null ) {
	    final String dbUrl = "jdbc:postgresql://localhost/weblog";
	    final Properties dbProps = new Properties();
	    dbProps.setProperty("user", "david");
	    dbProps.setProperty("password", "IHATETHISWHYCANTIUSEUNIXDOMAINSOCKETS");
	    dbProps.setProperty("ssl", "true");
	    dbProps.setProperty("sslfactory", "org.postgresql.ssl.NonValidatingFactory");
	    conn = (new Driver()).connect(dbUrl, dbProps);
	    conn.createStatement().execute("SET TIME ZONE 0");
	}
	return conn;
    }

}