当前位置: 首页>>代码示例>>Java>>正文


Java PGSimpleDataSource.getConnection方法代码示例

本文整理汇总了Java中org.postgresql.ds.PGSimpleDataSource.getConnection方法的典型用法代码示例。如果您正苦于以下问题:Java PGSimpleDataSource.getConnection方法的具体用法?Java PGSimpleDataSource.getConnection怎么用?Java PGSimpleDataSource.getConnection使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.postgresql.ds.PGSimpleDataSource的用法示例。


在下文中一共展示了PGSimpleDataSource.getConnection方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
 
开发者ID:spyhunter99,项目名称:installcert,代码行数:20,代码来源:StarttlsHandlerPOSTGRES.java

示例2: 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();
	}
}
 
开发者ID:freiheit-com,项目名称:sqlapi4j,代码行数:17,代码来源:SqlApiTest.java

示例3: 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();
	}
}
 
开发者ID:freiheit-com,项目名称:sqlapi4j,代码行数:17,代码来源:SqlApiTest.java

示例4: 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;
	}

}
 
开发者ID:jotpe,项目名称:regio-osm,代码行数:25,代码来源:TestPostprocessing.java

示例5: 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;
    }
}
 
开发者ID:PacktPublishing,项目名称:Java-9-Cookbook,代码行数:14,代码来源:Chapter06Database01.java

示例6: INIT

import org.postgresql.ds.PGSimpleDataSource; //导入方法依赖的package包/类
public static synchronized void INIT() {

        PGSimpleDataSource ds = new PGSimpleDataSource();
        ds.setUrl(PG_URL);

        try (final Connection cnx = ds.getConnection(); final Statement st = cnx.createStatement()) {
            st.execute(TestSuite.getResourceAsString(PG_SQL));
        } catch (Exception ex) {
            throw new RuntimeException(ex);
        }

        TestSuite.setupSessionFactoryBuilder(ds);
    }
 
开发者ID:javaplugs,项目名称:mybatis-types,代码行数:14,代码来源:PostgresqlSuite.java

示例7: getConnection

import org.postgresql.ds.PGSimpleDataSource; //导入方法依赖的package包/类
/**
 * Returns a manual commit, read uncommitted connection.
 */
public static Connection getConnection(final String jdbcURL)
{
  // for the time being, only postgresql
  if (!jdbcURL.startsWith("jdbc:postgresql"))
  {
    return null;
  }
  // try
  // {
  // Class.forName("org.postgresql.Driver");
  // }
  // catch (final ClassNotFoundException e)
  // {
  // e.printStackTrace();
  // return null;
  // }
  try
  {
    // jdbc:postgresql://localhost/jive?user=jive&password=
    final PGSimpleDataSource ds = new PGSimpleDataSource();
    ds.setUser("jive");
    ds.setDatabaseName("jive");
    ds.setServerName("localhost");
    ds.setPassword("");
    final Connection conn = ds.getConnection();
    conn.setAutoCommit(false);
    conn.setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
    return conn;
  }
  catch (final SQLException e)
  {
    e.printStackTrace();
  }
  return null;
}
 
开发者ID:UBPL,项目名称:jive,代码行数:39,代码来源:JDBCTools.java

示例8: dropNamespace

import org.postgresql.ds.PGSimpleDataSource; //导入方法依赖的package包/类
/**
 * Drops a namespace in the database.
 * 
 * <b>Postcondition:</b>Assumes {@link this.hasNamespace()} == true
 * 
 */
public void dropNamespace(String rootUser, String rootPass)
{
  // root needs to log into the application database to create the schema.
  PGSimpleDataSource tempRootDatasource = new PGSimpleDataSource();
  tempRootDatasource.setServerName(DatabaseProperties.getServerName());
  tempRootDatasource.setPortNumber(DatabaseProperties.getPort());
  tempRootDatasource.setDatabaseName(DatabaseProperties.getDatabaseName());
  tempRootDatasource.setUser(rootUser);
  tempRootDatasource.setPassword(rootPass);

  Connection conn = null;
  Statement statement = null;

  try
  {
    conn = tempRootDatasource.getConnection();
    statement = conn.createStatement();
    statement.execute(" DROP SCHEMA " + this.getNamespace() + " CASCADE");
  }
  catch (SQLException e)
  {
    throw new DatabaseException(e);
  }
  finally
  {
    try
    {
      if (statement != null)
      {
        statement.close();
      }
      if (conn != null)
      {
        conn.close();
      }
    }
    catch (Exception exception)
    {
    }
  }
}
 
开发者ID:terraframe,项目名称:Runway-SDK,代码行数:48,代码来源:PostgreSQL.java

示例9: createNamespace

import org.postgresql.ds.PGSimpleDataSource; //导入方法依赖的package包/类
/**
 * Creates a namespace in the database.
 * 
 * <b>Postcondition:</b>Assumes {@link this.hasNamespace()} == true
 * 
 */
public void createNamespace(String rootUser, String rootPass)
{
  // root needs to log into the application database to create the schema.
  PGSimpleDataSource tempRootDatasource = new PGSimpleDataSource();
  tempRootDatasource.setServerName(DatabaseProperties.getServerName());
  tempRootDatasource.setPortNumber(DatabaseProperties.getPort());
  tempRootDatasource.setDatabaseName(DatabaseProperties.getDatabaseName());
  tempRootDatasource.setUser(rootUser);
  tempRootDatasource.setPassword(rootPass);

  Connection conn = null;
  Statement statement = null;

  try
  {
    String userName = DatabaseProperties.getUser();
    String namespace = this.getNamespace();

    conn = tempRootDatasource.getConnection();
    statement = conn.createStatement();
    if (!namespace.trim().equals(userName.trim()))
    {
      statement.execute("CREATE SCHEMA " + namespace + " AUTHORIZATION " + userName);
    }
    else
    {
      statement.execute("ALTER SCHEMA " + namespace + " OWNER TO " + userName);
    }

    LinkedList<String> statements = new LinkedList<String>();
    statements.add("ALTER USER " + userName + " SET search_path = " + namespace + ", public");
    executeAsRoot(statements, true);

  }
  catch (SQLException e)
  {
    throw new DatabaseException(e);
  }
  finally
  {
    try
    {
      if (statement != null)
      {
        statement.close();
      }
      if (conn != null)
      {
        conn.close();
      }
    }
    catch (Exception exception)
    {
    }
  }
}
 
开发者ID:terraframe,项目名称:Runway-SDK,代码行数:63,代码来源:PostgreSQL.java


注:本文中的org.postgresql.ds.PGSimpleDataSource.getConnection方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。