本文整理汇总了Java中com.mysql.jdbc.MySQLConnection.close方法的典型用法代码示例。如果您正苦于以下问题:Java MySQLConnection.close方法的具体用法?Java MySQLConnection.close怎么用?Java MySQLConnection.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.mysql.jdbc.MySQLConnection
的用法示例。
在下文中一共展示了MySQLConnection.close方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testBug23201930
import com.mysql.jdbc.MySQLConnection; //导入方法依赖的package包/类
/**
* Tests fix for Bug#23201930 - CLIENT HANG WHEN RSLT CUNCURRENCY=CONCUR_UPDATABLE AND RSLTSET TYPE=FORWARD_ONLY.
*/
public void testBug23201930() throws Exception {
boolean useSSL = false;
boolean useSPS = false;
boolean useCursor = false;
boolean useCompr = false;
final char[] chars = new char[32 * 1024];
Arrays.fill(chars, 'x');
final String longData = String.valueOf(chars); // Using large data makes SSL connections hang sometimes.
do {
final String testCase = String.format("Case [SSL: %s, SPS: %s, Cursor: %s, Compr: %s]", useSSL ? "Y" : "N", useSPS ? "Y" : "N",
useCursor ? "Y" : "N", useCompr ? "Y" : "N");
createTable("testBug23201930", "(id TINYINT AUTO_INCREMENT PRIMARY KEY, f1 INT DEFAULT 1, f2 INT DEFAULT 1, f3 INT DEFAULT 1, "
+ "f4 INT DEFAULT 1, f5 INT DEFAULT 1, fl LONGBLOB)");
final Properties props = new Properties();
props.setProperty("useSSL", Boolean.toString(useSSL));
if (useSSL) {
props.setProperty("requireSSL", "true");
props.setProperty("verifyServerCertificate", "false");
}
props.setProperty("useServerPrepStmts", Boolean.toString(useSPS));
props.setProperty("useCursorFetch", Boolean.toString(useCursor));
if (useCursor) {
props.setProperty("defaultFetchSize", "1");
}
props.setProperty("useCompression", Boolean.toString(useCompr));
final MySQLConnection testConn = (MySQLConnection) getConnectionWithProps(props);
final ExecutorService executor = Executors.newSingleThreadExecutor();
final Future<Void> future = executor.submit(new Callable<Void>() {
public Void call() throws Exception {
final Statement testStmt = testConn.createStatement();
testStmt.execute("INSERT INTO testBug23201930 (id) VALUES (100)");
PreparedStatement testPstmt = testConn.prepareStatement("INSERT INTO testBug23201930 (id, fl) VALUES (?, ?)", ResultSet.TYPE_FORWARD_ONLY,
ResultSet.CONCUR_UPDATABLE);
testPstmt.setObject(1, 101, java.sql.Types.INTEGER);
testPstmt.setObject(2, longData, java.sql.Types.VARCHAR);
testPstmt.execute();
testPstmt.setObject(1, 102, java.sql.Types.INTEGER);
testPstmt.execute();
testPstmt.close();
testPstmt = testConn.prepareStatement("SELECT * FROM testBug23201930 WHERE id >= ? ORDER BY id ASC", ResultSet.TYPE_FORWARD_ONLY,
ResultSet.CONCUR_UPDATABLE);
testPstmt.setObject(1, 100, java.sql.Types.INTEGER);
final ResultSet testRs = testPstmt.executeQuery();
assertTrue(testRs.next());
assertEquals(100, testRs.getInt(1));
assertTrue(testRs.next());
assertEquals(101, testRs.getInt(1));
assertTrue(testRs.next());
assertEquals(102, testRs.getInt(1));
assertFalse(testRs.next());
testPstmt.close();
return null;
}
});
try {
future.get(10, TimeUnit.SECONDS);
} catch (TimeoutException e) {
// The connection hung, forcibly closing it releases resources.
this.stmt.executeQuery("KILL CONNECTION " + testConn.getId());
fail(testCase + ": Connection hung!");
}
executor.shutdownNow();
testConn.close();
} while ((useSSL = !useSSL) || (useSPS = !useSPS) || (useCursor = !useCursor) || (useCompr = !useCompr)); // Cycle through all possible combinations.
}