本文整理汇总了Java中com.impossibl.postgres.jdbc.PGDataSource.getConnection方法的典型用法代码示例。如果您正苦于以下问题:Java PGDataSource.getConnection方法的具体用法?Java PGDataSource.getConnection怎么用?Java PGDataSource.getConnection使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.impossibl.postgres.jdbc.PGDataSource
的用法示例。
在下文中一共展示了PGDataSource.getConnection方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: startNotificationListener
import com.impossibl.postgres.jdbc.PGDataSource; //导入方法依赖的package包/类
@Override
public void startNotificationListener(DBMSSynchronizer dbmsSynchronizer) {
// Disable cleanup output of ThreadedHousekeeper
Logger.getLogger(ThreadedHousekeeper.class.getName()).setLevel(Level.SEVERE);
this.listener = new PostgresSQLNotificationListener(dbmsSynchronizer);
PGDataSource dataSource = new PGDataSource();
dataSource.setHost(connectionProperties.getHost());
dataSource.setPort(connectionProperties.getPort());
dataSource.setDatabase(connectionProperties.getDatabase());
dataSource.setUser(connectionProperties.getUser());
dataSource.setPassword(connectionProperties.getPassword());
try {
pgConnection = (PGConnection) dataSource.getConnection();
pgConnection.createStatement().execute("LISTEN jabrefLiveUpdate");
// Do not use `new PostgresSQLNotificationListener(...)` as the object has to exist continuously!
// Otherwise the listener is going to be deleted by GC.
pgConnection.addNotificationListener(listener);
} catch (SQLException e) {
LOGGER.error("SQL Error: ", e);
}
}
示例2: createDataSource
import com.impossibl.postgres.jdbc.PGDataSource; //导入方法依赖的package包/类
@SneakyThrows
public static PGDataSource createDataSource() {
if (pgConfig == null) {
pgConfig = launchPostgres();
}
PGDataSource ds = new PGDataSource();
ds.setHost(pgConfig.net().host());
ds.setDatabase(pgConfig.storage().dbName());
ds.setUser(pgConfig.credentials().username());
ds.setPassword(pgConfig.credentials().password());
ds.setPort(pgConfig.net().port());
ds.setHousekeeper(false);
String databaseName = UUID.randomUUID().toString();
try (Connection c = ds.getConnection()) {
try (PreparedStatement preparedStatement = c.prepareStatement("CREATE DATABASE \"" + databaseName + "\"")) {
preparedStatement.executeUpdate();
}
}
ds.setDatabase(databaseName);
return ds;
}