本文整理汇总了Java中javax.sql.ConnectionPoolDataSource.getPooledConnection方法的典型用法代码示例。如果您正苦于以下问题:Java ConnectionPoolDataSource.getPooledConnection方法的具体用法?Java ConnectionPoolDataSource.getPooledConnection怎么用?Java ConnectionPoolDataSource.getPooledConnection使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.sql.ConnectionPoolDataSource
的用法示例。
在下文中一共展示了ConnectionPoolDataSource.getPooledConnection方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: embeddedTestAttributesAsPasswordWithPassword_pooled
import javax.sql.ConnectionPoolDataSource; //导入方法依赖的package包/类
/**
* Tests that the <code>attributesAsPassword</code> property of a
* <code>ConnectionPoolDataSource</code> causes an explicitly specified
* password to be sent as a property string.
*/
public void embeddedTestAttributesAsPasswordWithPassword_pooled()
throws Exception
{
ConnectionPoolDataSource ds =
J2EEDataSource.getConnectionPoolDataSource();
JDBCDataSource.setBeanProperty(ds, "attributesAsPassword", Boolean.TRUE);
try {
PooledConnection pc =
ds.getPooledConnection("username", "mypassword");
fail("Expected getPooledConnection to fail.");
} catch (SQLException e) {
// expect error because of malformed url
assertSQLState("XJ028", e);
}
}
示例2: testCacheOverflow
import javax.sql.ConnectionPoolDataSource; //导入方法依赖的package包/类
/**
* Tests that the statement cache is able to throw out prepared statements
* when it reaches maximum capacity.
*
* @throws SQLException if something goes wrong...
*/
public void testCacheOverflow()
throws SQLException {
final int stmtCount = 150;
ConnectionPoolDataSource cpDs =
J2EEDataSource.getConnectionPoolDataSource();
J2EEDataSource.setBeanProperty(cpDs, "maxStatements", new Integer(11));
J2EEDataSource.setBeanProperty(cpDs, "createDatabase", "create");
PooledConnection pc = cpDs.getPooledConnection();
Connection con = pc.getConnection();
for (int i=0; i < stmtCount; i++) {
// Yes, the "values + i" is intended here.
PreparedStatement pStmt = con.prepareStatement("values " + i);
ResultSet rs = pStmt.executeQuery();
JDBC.assertSingleValueResultSet(rs, Integer.toString(i));
pStmt.close();
}
con.close();
pc.close();
}
示例3: doTestHoldabilityIsReset
import javax.sql.ConnectionPoolDataSource; //导入方法依赖的package包/类
/**
* Test sequence for testing if the connection holdability is reset.
*
* @param closeConnection determines if the logical connection is
* explicitly closed before a new one is obtained
* @throws SQLException if something goes wrong...
*/
private void doTestHoldabilityIsReset(final boolean closeConnection)
throws SQLException {
ConnectionPoolDataSource cpDs =
J2EEDataSource.getConnectionPoolDataSource();
J2EEDataSource.setBeanProperty(cpDs, "maxStatements", new Integer(7));
J2EEDataSource.setBeanProperty(cpDs, "createDatabase", "create");
PooledConnection pc = cpDs.getPooledConnection();
// Keep track of our own connection, the framework currently creates
// a new pooled connection and then obtains a connection from that.
// Statement pooling only works within a single pooled connection.
Connection con = pc.getConnection();
assertEquals("Unexpected default holdability",
ResultSet.HOLD_CURSORS_OVER_COMMIT, con.getHoldability());
con.setHoldability(ResultSet.CLOSE_CURSORS_AT_COMMIT);
assertEquals("Holdability not updated",
ResultSet.CLOSE_CURSORS_AT_COMMIT, con.getHoldability());
if (closeConnection) {
con.close();
}
con = pc.getConnection();
assertEquals("Holdability not reset",
ResultSet.HOLD_CURSORS_OVER_COMMIT, con.getHoldability());
pc.close();
}
示例4: assertShutdownWOUPOK
import javax.sql.ConnectionPoolDataSource; //导入方法依赖的package包/类
protected void assertShutdownWOUPOK(
String dbName, String user, String password)
throws SQLException {
ConnectionPoolDataSource pds = J2EEDataSource.getConnectionPoolDataSource();
JDBCDataSource.setBeanProperty(pds, "databaseName", dbName);
JDBCDataSource.setBeanProperty(pds, "user", user);
JDBCDataSource.setBeanProperty(pds, "password", password);
JDBCDataSource.setBeanProperty(pds, "shutdownDatabase","shutdown");
try {
pds.getPooledConnection();
fail ("expected a failed shutdown connection");
} catch (SQLException e) {
// expect 08006 on successful shutdown
assertSQLState("08006", e);
}
}
示例5: timeoutTestDerby1144PooledDS
import javax.sql.ConnectionPoolDataSource; //导入方法依赖的package包/类
/**
* Tests for DERBY-1144
*
* This test tests that holdability, autocomit, and transactionIsolation
* are reset on getConnection for PooledConnections obtaind from
* connectionPoolDataSources
*
* DERBY-1134 has been filed for more comprehensive testing of client
* connection state.
*
* @throws SQLException
*/
public void timeoutTestDerby1144PooledDS() throws SQLException {
PooledConnection pc1 = null;
// Test holdability
ConnectionPoolDataSource ds =
J2EEDataSource.getConnectionPoolDataSource();
pc1 = ds.getPooledConnection();
assertPooledConnHoldability("PooledConnection", pc1);
pc1.close();
// Test autocommit
pc1 = ds.getPooledConnection();
assertPooledConnAutoCommit("PooledConnection", pc1);
pc1.close();
// Test pooled connection isolation
pc1 = ds.getPooledConnection();
assertPooledConnIso("PooledConnection" , pc1);
pc1.close();
}
示例6: assertSystemShutdownFail
import javax.sql.ConnectionPoolDataSource; //导入方法依赖的package包/类
protected void assertSystemShutdownFail(
String expectedError, String dbName, String user, String password)
throws SQLException {
ConnectionPoolDataSource pds = J2EEDataSource.getConnectionPoolDataSource();
JDBCDataSource.clearStringBeanProperty(pds, "databaseName");
JDBCDataSource.setBeanProperty(pds, "databaseName", dbName);
JDBCDataSource.setBeanProperty(pds, "shutdownDatabase", "shutdown");
JDBCDataSource.setBeanProperty(pds, "user", user);
JDBCDataSource.setBeanProperty(pds, "password", password);
try {
pds.getPooledConnection();
fail("expected shutdown to fail");
} catch (SQLException e) {
assertSQLState(expectedError, e);
}
}
示例7: dsConnectionRequests
import javax.sql.ConnectionPoolDataSource; //导入方法依赖的package包/类
private static void dsConnectionRequests(
String[] expectedValues, ConnectionPoolDataSource ds) {
try {
ds.getPooledConnection();
if (!expectedValues[0].equals("OK"))
fail (" expected connection to fail, but was OK");
} catch (SQLException sqle) {
assertSQLState(expectedValues[0], sqle);
}
dsConnectionRequest(expectedValues[1], ds, null, null);
dsConnectionRequest(expectedValues[2], ds, "fred", null);
dsConnectionRequest(expectedValues[3], ds, "fred", "wilma");
dsConnectionRequest(expectedValues[4], ds, null, "wilma");
dsConnectionRequest(
expectedValues[5], ds, null, "databaseName=wombat");
dsConnectionRequest(
expectedValues[6], ds, "fred", "databaseName=wombat");
dsConnectionRequest(expectedValues[7],
ds, "fred", "databaseName=wombat;password=wilma");
dsConnectionRequest(expectedValues[8],
ds, "fred", "databaseName=wombat;password=betty");
}
示例8: testConnectionFlowCommit
import javax.sql.ConnectionPoolDataSource; //导入方法依赖的package包/类
/**
* check whether commit without statement will flow by checking its transaction id
* on client. This test is run only for client where commits without an
* active transactions will not flow to the server.
* DERBY-4653
*
* @throws SQLException
**/
public void testConnectionFlowCommit()
throws SQLException {
ConnectionPoolDataSource ds = J2EEDataSource.getConnectionPoolDataSource();
PooledConnection pc = ds.getPooledConnection();
Connection conn = pc.getConnection();
testConnectionFlowCommitWork(conn, 1);
conn.close();
//Test for XADataSource
XADataSource xs = J2EEDataSource.getXADataSource();
XAConnection xc = xs.getXAConnection();
conn = xc.getConnection();
testConnectionFlowCommitWork(conn, 1);
conn.close();
//Test for DataSource
DataSource jds = JDBCDataSource.getDataSource();
conn = jds.getConnection();
testConnectionFlowCommitWork(conn, 1);
conn.close();
}
示例9: testJira95pds
import javax.sql.ConnectionPoolDataSource; //导入方法依赖的package包/类
public void testJira95pds() throws Exception {
try {
ConnectionPoolDataSource pds = J2EEDataSource.getConnectionPoolDataSource();
JDBCDataSource.setBeanProperty(pds, "databaseName", "jdbc:derby:boo");
pds.getPooledConnection();
fail ("expected an SQLException!");
} catch (SQLException sqle) {
// DERBY-2498 - when fixed, remove if
if (usingEmbedded())
assertSQLState("XCY00", sqle);
} catch (Exception e) {
// DERBY-2498 - when fixed, remove if
if (usingEmbedded())
throw e;
}
}
示例10: testPooledConnectionStatementError
import javax.sql.ConnectionPoolDataSource; //导入方法依赖的package包/类
@Test
public void testPooledConnectionStatementError() throws Exception {
ConnectionPoolDataSource ds = new MariaDbDataSource(hostname != null ? hostname : "localhost", port, database);
PooledConnection pc = ds.getPooledConnection(username, password);
MyEventListener listener = new MyEventListener();
pc.addStatementEventListener(listener);
MariaDbConnection connection = (MariaDbConnection) pc.getConnection();
try (PreparedStatement ps = connection.prepareStatement("SELECT ?")) {
ps.execute();
fail("should never get there");
} catch (Exception e) {
assertTrue(listener.statementErrorOccured);
if (sharedBulkCapacity()) {
assertTrue(e.getMessage().contains("Parameter at position 1 is not set")
|| e.getMessage().contains("Incorrect arguments to mysqld_stmt_execute"));
} else {
//HY000 if server >= 10.2 ( send prepare and query in a row), 07004 otherwise
assertTrue("07004".equals(listener.sqlException.getSQLState()) || "HY000".equals(listener.sqlException.getSQLState()));
}
}
assertTrue(listener.statementClosed);
pc.close();
}
示例11: assertConnectionWOUPFail
import javax.sql.ConnectionPoolDataSource; //导入方法依赖的package包/类
protected void assertConnectionWOUPFail(
String expectedSqlState, String dbName, String user, String password)
throws SQLException
{
ConnectionPoolDataSource pds = J2EEDataSource.getConnectionPoolDataSource();
JDBCDataSource.setBeanProperty(pds, "databaseName", dbName);
JDBCDataSource.setBeanProperty(pds, "user", user);
JDBCDataSource.setBeanProperty(pds, "password", password);
try {
pds.getPooledConnection();
fail("Connection should've been refused/failed");
}
catch (SQLException e) {
assertSQLState(expectedSqlState, e);
}
}
示例12: assertShutdownWOUPFail
import javax.sql.ConnectionPoolDataSource; //导入方法依赖的package包/类
protected void assertShutdownWOUPFail(
String expectedSqlState, String dbName, String user, String password)
throws SQLException
{
ConnectionPoolDataSource pds = J2EEDataSource.getConnectionPoolDataSource();
JDBCDataSource.setBeanProperty(pds, "shutdownDatabase", "shutdown");
JDBCDataSource.setBeanProperty(pds, "user", user);
JDBCDataSource.setBeanProperty(pds, "password", password);
JDBCDataSource.setBeanProperty(pds, "databaseName", dbName);
try {
pds.getPooledConnection();
fail("expected failed shutdown");
} catch (SQLException e) {
assertSQLState(expectedSqlState, e);
}
}
示例13: assertConnectionFail
import javax.sql.ConnectionPoolDataSource; //导入方法依赖的package包/类
public void assertConnectionFail(String dbName) throws SQLException {
ConnectionPoolDataSource pds = J2EEDataSource.getConnectionPoolDataSource();
// Reset to no user/password though client requires
// a valid name, so reset to the default
if (usingDerbyNetClient())
JDBCDataSource.setBeanProperty(pds, "user", "APP");
else
JDBCDataSource.clearStringBeanProperty(pds, "user");
JDBCDataSource.clearStringBeanProperty(pds, "password");
JDBCDataSource.setBeanProperty(pds, "databaseName", dbName);
try {
pds.getPooledConnection();
fail("expected connection to fail");
} catch (SQLException e) {
assertSQLState("08004", e);
}
}
示例14: dsConnectionRequests
import javax.sql.ConnectionPoolDataSource; //导入方法依赖的package包/类
private static void dsConnectionRequests(
String[] expectedValues, ConnectionPoolDataSource ds) {
try {
ds.getPooledConnection();
if (!expectedValues[0].equals("OK"))
fail (" expected connection to fail, but was OK");
} catch (SQLException sqle) {
assertSQLState(expectedValues[0], sqle);
}
dsConnectionRequest(expectedValues[1], ds, null, null);
dsConnectionRequest(expectedValues[2], ds, "fred", null);
dsConnectionRequest(expectedValues[3], ds, "fred", "wilma");
dsConnectionRequest(expectedValues[4], ds, null, "wilma");
dsConnectionRequest(
expectedValues[5], ds, null, "databaseName=wombat");
dsConnectionRequest(
expectedValues[6], ds, "fred", "databaseName=wombat");
dsConnectionRequest(expectedValues[7],
ds, "fred", "databaseName=wombat;password=wilma");
dsConnectionRequest(expectedValues[8],
ds, "fred", "databaseName=wombat;password=betty");
}
示例15: testDerby3799
import javax.sql.ConnectionPoolDataSource; //导入方法依赖的package包/类
/**
* Regression test for a NullPointerException when trying to use the LOB
* stored procedures after closing and then getting a new logical
* connection. The problem was that the LOB stored procedure objects on the
* server side were closed and not reprepared.
* See Jira issue DERBY-3799.
*/
public void testDerby3799() throws SQLException {
ConnectionPoolDataSource cpDs =
J2EEDataSource.getConnectionPoolDataSource();
PooledConnection pc = cpDs.getPooledConnection();
// Get first logical connection.
Connection con1 = pc.getConnection();
Statement stmt = con1.createStatement();
ResultSet rs = stmt.executeQuery("select dClob from derby3799");
assertTrue(rs.next());
rs.getString(1);
rs.close();
con1.close();
// Get second logical connection.
Connection con2 = pc.getConnection();
stmt = con2.createStatement();
rs = stmt.executeQuery("select dClob from derby3799");
assertTrue(rs.next());
rs.getString(1); // NPE happened here.
con2.close();
}