a8d28f9bb0a3b6700a92953bb00f3589cf01bb29
[cfb.git] / prod / net / jaekl / cfb / db / driver / PostgresqlDriver.java
1 package net.jaekl.cfb.db.driver;
2
3 // Copyright (C) 2015 Christian Jaekl
4
5 import java.sql.Connection;
6 import java.sql.DriverManager;
7 import java.sql.SQLException;
8 import java.util.Properties;
9
10 public class PostgresqlDriver extends DbDriver {
11
12         @Override
13         public void load() throws ClassNotFoundException {
14                 // This should no longer be necessary, so long as we're using 
15                 // JDBC 4 (which came out with JDK 6) and an updated driver.
16                 // But, it shouldn't hurt, either.
17                 Class.forName("org.postgresql.Driver");
18         }
19
20         @Override
21         public Connection connect(String host, int port, String dbName, String user, String pass) throws SQLException {
22                 String url = "jdbc:postgresql://" + host + ":" + port + "/" + dbName;
23                 Properties props = new Properties();
24                 props.setProperty("user", user);
25                 props.setProperty("password", pass);
26                 //props.setProperty("ssl", "true");
27                 return DriverManager.getConnection(url, props);
28         }
29 }