本文整理汇总了Java中org.postgresql.ds.PGSimpleDataSource类的典型用法代码示例。如果您正苦于以下问题:Java PGSimpleDataSource类的具体用法?Java PGSimpleDataSource怎么用?Java PGSimpleDataSource使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PGSimpleDataSource类属于org.postgresql.ds包,在下文中一共展示了PGSimpleDataSource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: run
import org.postgresql.ds.PGSimpleDataSource; //导入依赖的package包/类
@Override
public boolean run(String host, int port,Socket tunnel) throws Exception {
try {
PGSimpleDataSource ds = new PGSimpleDataSource();
ds.setServerName(host);
ds.setPortNumber(port);
ds.setSsl(true);
///this.sslContext = InstallCert.getContext();
ds.setSslfactory(host);
ds.setSslfactory(DumperFactory.class.getName());
Connection c = ds.getConnection();
c.close();
return true;
} catch (Exception ex) {
System.out.println(ex.getMessage());
}
return false;
}
示例2: postgreDataSource
import org.postgresql.ds.PGSimpleDataSource; //导入依赖的package包/类
private static DataSource postgreDataSource() {
synchronized (LOCK) {
if (dataSource == null) {
final PGSimpleDataSource pgDataSource = new PGSimpleDataSource();
pgDataSource.setServerName("localhost");
pgDataSource.setPortNumber(5432);
pgDataSource.setDatabaseName("iws");
pgDataSource.setUser("iws_user");
pgDataSource.setPassword("iws");
dataSource = pgDataSource;
}
return dataSource;
}
}
示例3: getDataSourceLocator
import org.postgresql.ds.PGSimpleDataSource; //导入依赖的package包/类
@Override
public SQLDataSourceLocator getDataSourceLocator() {
return new SQLDataSourceLocator() {
public DataSource lookup(SQLDataSetDef def) throws Exception {
String server = connectionSettings.getProperty("server");
String database = connectionSettings.getProperty("database");
String port = connectionSettings.getProperty("port");
String user = connectionSettings.getProperty("user");
String password = connectionSettings.getProperty("password");
PGSimpleDataSource ds = new PGSimpleDataSource();
ds.setServerName(server);
ds.setDatabaseName(database);
ds.setPortNumber(Integer.parseInt(port));
if (!StringUtils.isBlank(user)) {
ds.setUser(user);
}
if (!StringUtils.isBlank(password)) {
ds.setPassword(password);
}
return ds;
}
};
}
示例4: getDatabase
import org.postgresql.ds.PGSimpleDataSource; //导入依赖的package包/类
public DataSource getDatabase(String userName, String dbName, Map<String, String> properties)
{
final PGSimpleDataSource ds = new PGSimpleDataSource();
ds.setServerName("localhost");
ds.setPortNumber(port);
ds.setDatabaseName(dbName);
ds.setUser(userName);
properties.forEach((propertyKey, propertyValue) -> {
try {
ds.setProperty(propertyKey, propertyValue);
} catch (SQLException e) {
throw new RuntimeException(e);
}
});
return ds;
}
示例5: Pagerank
import org.postgresql.ds.PGSimpleDataSource; //导入依赖的package包/类
public Pagerank(String postgresql) throws ClassNotFoundException, SQLException, IOException{
//inits
Class.forName("org.postgresql.Driver");
this.ds = new PGSimpleDataSource();
ds.setUrl(postgresql);
ds.setUser("postgres");
ds.setPassword("postgres");
this.conn = ds.getConnection();
loadData();
size = sizeHaltestellen();
P = new double[size][size];
System.out.println("size: " + size);
// fill P
for(int i = 0; i<size; i++){
for(int j = 0; j<size; j++){
P[i][j] = 0;
}
}
fillP();
// printP();
}
示例6: initialSetup
import org.postgresql.ds.PGSimpleDataSource; //导入依赖的package包/类
/**
* Installs the runway core. This entails creating a new database and a user
* for the runway to log in with.
*/
public void initialSetup(String rootUser, String rootPass, String rootDb)
{
// Set up the root connection
BaseDataSource pgRootDataSource = new PGSimpleDataSource();
pgRootDataSource.setServerName(DatabaseProperties.getServerName());
pgRootDataSource.setPortNumber(DatabaseProperties.getPort());
pgRootDataSource.setDatabaseName(rootDb);
pgRootDataSource.setUser(rootUser);
pgRootDataSource.setPassword(rootPass);
this.rootDataSource = (DataSource) pgRootDataSource;
// this.dropNamespace(rootUser, rootPass);
this.dropDb();
this.dropUser();
this.createDb(rootDb);
this.createUser();
if (this.hasNamespace())
{
this.createNamespace(rootUser, rootPass);
}
}
示例7: main
import org.postgresql.ds.PGSimpleDataSource; //导入依赖的package包/类
public static void main( final String[] args) {
System.out.println( "------------ starting tests --------------------\n");
final PGSimpleDataSource ds= new PGSimpleDataSource();
ds.setDatabaseName( "reporting");
ds.setServerName( "127.0.0.1");
ds.setUser( "reporting");
ds.setPassword( "reporting");
doResultTest( ds);
//testQueryAllCols( ds);
testQueryCount( ds);
testGroupCount( ds);
testWhereIn( ds);
testSubselect( ds);
doResultTestGC( ds);
testInsertUpdate();
queryTest();
System.out.println( "\n------------ finished tests --------------------");
}
示例8: doResultTest
import org.postgresql.ds.PGSimpleDataSource; //导入依赖的package包/类
private static void doResultTest( final PGSimpleDataSource ds) {
try {
final Connection conn= ds.getConnection();
try {
resultSetTest( ds.getConnection());
} catch( final SQLException e) {
e.printStackTrace();
} finally {
if( conn != null) {
conn.close();
}
}
} catch( final SQLException e1) {
e1.printStackTrace();
}
}
示例9: doResultTestGC
import org.postgresql.ds.PGSimpleDataSource; //导入依赖的package包/类
private static void doResultTestGC( final PGSimpleDataSource ds) {
try {
final Connection conn= ds.getConnection();
try {
resultSetTestGroupCount( ds.getConnection());
} catch( final SQLException e) {
e.printStackTrace();
} finally {
if( conn != null) {
conn.close();
}
}
} catch( final SQLException e1) {
e1.printStackTrace();
}
}
示例10: getConnection
import org.postgresql.ds.PGSimpleDataSource; //导入依赖的package包/类
public Connection getConnection() throws IOException {
PGSimpleDataSource dataSource = new PGSimpleDataSource();
Properties dataSourceProperties = new Properties();
dataSourceProperties.load(getClass().getResourceAsStream(
"datasource-test.properties"));
dataSource
.setServerName(dataSourceProperties.getProperty("serverName"));
dataSource.setDatabaseName(dataSourceProperties
.getProperty("databaseName"));
dataSource.setPortNumber(Integer.parseInt(dataSourceProperties
.getProperty("portNumber")));
dataSource.setUser(dataSourceProperties.getProperty("user"));
dataSource.setPassword(dataSourceProperties.getProperty("password"));
try {
return dataSource.getConnection();
} catch (Exception e) {
IllegalArgumentException e1 = new IllegalArgumentException(
"couldn't open database connection: " + e.getMessage());
e1.initCause(e);
throw e1;
}
}
示例11: getDbConnection2
import org.postgresql.ds.PGSimpleDataSource; //导入依赖的package包/类
private static Connection getDbConnection2(){
PGSimpleDataSource source = new PGSimpleDataSource();
source.setServerName("localhost");
source.setDatabaseName("cookbook");
source.setLoginTimeout(10);
try {
return source.getConnection();
}
catch(Exception ex) {
ex.printStackTrace();
return null;
}
}
示例12: getDataSources
import org.postgresql.ds.PGSimpleDataSource; //导入依赖的package包/类
@Parameters(name = "{index}:{0}")
public static Collection<DataSource> getDataSources() {
List<DataSource> dataSources = new ArrayList<>();
dataSources.add(newH2DataSource());
// MySQL
if (HekateTestProps.is("MYSQL_ENABLED")) {
MysqlDataSource mysql = new MysqlDataSource();
mysql.setURL(HekateTestProps.get("MYSQL_URL"));
mysql.setUser(HekateTestProps.get("MYSQL_USER"));
mysql.setPassword(HekateTestProps.get("MYSQL_PASSWORD"));
dataSources.add(mysql);
}
// PostgreSQL
if (HekateTestProps.is("POSTGRES_ENABLED")) {
PGSimpleDataSource postgres = new PGSimpleDataSource();
postgres.setUrl(HekateTestProps.get("POSTGRES_URL"));
postgres.setUser(HekateTestProps.get("POSTGRES_USER"));
postgres.setPassword(HekateTestProps.get("POSTGRES_PASSWORD"));
dataSources.add(postgres);
}
return dataSources;
}
示例13: withPosgresSimpleDataSource
import org.postgresql.ds.PGSimpleDataSource; //导入依赖的package包/类
private DataSource withPosgresSimpleDataSource() {
PGSimpleDataSource ds = new PGSimpleDataSource();
ds.setUrl(String.format("jdbc:postgresql://%s:%s/%s", hostname, port, database));
ds.setUser(username);
ds.setPassword(password);
return ds;
}
示例14: toDb
import org.postgresql.ds.PGSimpleDataSource; //导入依赖的package包/类
private ConnectionPool toDb(DataSource source) {
if (source instanceof PGSimpleDataSource) {
return toDb((PGSimpleDataSource) source);
} else {
throw new IllegalStateException();
}
}
示例15: postgresDataSource
import org.postgresql.ds.PGSimpleDataSource; //导入依赖的package包/类
private static DataSource postgresDataSource() {
final PGSimpleDataSource dataSource = new PGSimpleDataSource();
dataSource.setServerName("localhost");
dataSource.setDatabaseName("iws");
dataSource.setUser("iws_user");
dataSource.setPassword("iws");
return dataSource;
}