日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

java jdbc reparecall_Java Connection.prepareCall方法代碼示例

發布時間:2023/12/10 49 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java jdbc reparecall_Java Connection.prepareCall方法代碼示例 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

本文整理匯總了Java中java.sql.Connection.prepareCall方法的典型用法代碼示例。如果您正苦於以下問題:Java Connection.prepareCall方法的具體用法?Java Connection.prepareCall怎麼用?Java Connection.prepareCall使用的例子?那麼恭喜您, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.sql.Connection的用法示例。

在下文中一共展示了Connection.prepareCall方法的16個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於我們的係統推薦出更棒的Java代碼示例。

示例1: testBug12417

?點讚 4

?

import java.sql.Connection; //導入方法依賴的package包/類

/**

* Tests fix for Bug#12417 - stored procedure catalog name is case-sensitive

* on Windows (this is actually a server bug, but we have a workaround in

* place for it now).

*

* @throws Exception

* if the test fails.

*/

public void testBug12417() throws Exception {

if (serverSupportsStoredProcedures() && isServerRunningOnWindows()) {

createProcedure("testBug12417", "()\nBEGIN\nSELECT 1;end\n");

Connection ucCatalogConn = null;

try {

ucCatalogConn = getConnectionWithProps((Properties) null);

ucCatalogConn.setCatalog(this.conn.getCatalog().toUpperCase());

ucCatalogConn.prepareCall("{call testBug12417()}");

} finally {

if (ucCatalogConn != null) {

ucCatalogConn.close();

}

}

}

}

開發者ID:bragex,項目名稱:the-vigilantes,代碼行數:27,

示例2: testBug78961

?點讚 3

?

import java.sql.Connection; //導入方法依賴的package包/類

/**

* Tests fix for Bug#78961 - Can't call MySQL procedure with InOut parameters in Fabric environment.

*

* Although this is a Fabric related bug we are able reproduce it using a couple of multi-host connections.

*/

public void testBug78961() throws Exception {

createProcedure("testBug78961", "(IN c1 FLOAT, IN c2 FLOAT, OUT h FLOAT, INOUT t FLOAT) BEGIN SET h = SQRT(c1 * c1 + c2 * c2); SET t = t + h; END;");

Connection highLevelConn = getLoadBalancedConnection(null);

assertTrue(highLevelConn.getClass().getName().startsWith("com.sun.proxy") || highLevelConn.getClass().getName().startsWith("$Proxy"));

Connection lowLevelConn = getMasterSlaveReplicationConnection(null);

// This simulates the behavior from Fabric connections that are causing the problem.

((ReplicationConnection) lowLevelConn).setProxy((MySQLConnection) highLevelConn);

CallableStatement cstmt = lowLevelConn.prepareCall("{CALL testBug78961 (?, ?, ?, ?)}");

cstmt.setFloat(1, 3.0f);

cstmt.setFloat(2, 4.0f);

cstmt.setFloat(4, 5.0f);

cstmt.registerOutParameter(3, Types.FLOAT);

cstmt.registerOutParameter(4, Types.FLOAT);

cstmt.execute();

assertEquals(5.0f, cstmt.getFloat(3));

assertEquals(10.0f, cstmt.getFloat(4));

}

開發者ID:Jugendhackt,項目名稱:OpenVertretung,代碼行數:27,

示例3: deleteTestcase

?點讚 3

?

import java.sql.Connection; //導入方法依賴的package包/類

public void deleteTestcase(

List objectsToDelete ) throws DatabaseAccessException {

StringBuilder testcaseIds = new StringBuilder();

for (Object obj : objectsToDelete) {

testcaseIds.append( ((Testcase) obj).testcaseId);

testcaseIds.append(",");

}

testcaseIds.delete(testcaseIds.length() - 1, testcaseIds.length());

final String errMsg = "Unable to delete testcase(s) with id " + testcaseIds;

Connection connection = getConnection();

CallableStatement callableStatement = null;

try {

callableStatement = connection.prepareCall("{ call sp_delete_testcase(?) }");

callableStatement.setString(1, testcaseIds.toString());

callableStatement.execute();

} catch (SQLException e) {

throw new DatabaseAccessException(errMsg, e);

} finally {

DbUtils.close(connection, callableStatement);

}

}

開發者ID:Axway,項目名稱:ats-framework,代碼行數:25,

示例4: getSuiteMessagesCount

?點讚 3

?

import java.sql.Connection; //導入方法依賴的package包/類

public int getSuiteMessagesCount( String whereClause ) throws DatabaseAccessException {

String sqlLog = new SqlRequestFormatter().add("where", whereClause).format();

Connection connection = getConnection();

CallableStatement callableStatement = null;

ResultSet rs = null;

try {

callableStatement = connection.prepareCall("{ call sp_get_suite_messages_count(?) }");

callableStatement.setString(1, whereClause);

rs = callableStatement.executeQuery();

int messagesCount = 0;

if (rs.next()) {

messagesCount = rs.getInt("messagesCount");

}

logQuerySuccess(sqlLog, "suite messages count", messagesCount);

return messagesCount;

} catch (Exception e) {

throw new DatabaseAccessException("Error when " + sqlLog, e);

} finally {

DbUtils.closeResultSet(rs);

DbUtils.close(connection, callableStatement);

}

}

開發者ID:Axway,項目名稱:ats-framework,代碼行數:27,

示例5: sendRequest

?點讚 3

?

import java.sql.Connection; //導入方法依賴的package包/類

protected void sendRequest(Document request) throws IOException {

try {

StringWriter writer = new StringWriter();

(new XMLWriter(writer,OutputFormat.createPrettyPrint())).write(request);

writer.flush(); writer.close();

SessionImplementor session = (SessionImplementor)new _RootDAO().getSession();

Connection connection = session.getJdbcConnectionAccess().obtainConnection();

try {

CallableStatement call = connection.prepareCall(iRequestSql);

call.setString(1, writer.getBuffer().toString());

call.execute();

call.close();

} finally {

session.getJdbcConnectionAccess().releaseConnection(connection);

}

} catch (Exception e) {

sLog.error("Unable to send request: "+e.getMessage(),e);

} finally {

_RootDAO.closeCurrentThreadSessions();

}

}

開發者ID:Jenner4S,項目名稱:unitimes,代碼行數:22,

示例6: getNumberOfCheckpointsPerQueue

?點讚 2

?

import java.sql.Connection; //導入方法依賴的package包/類

public Map

getNumberOfCheckpointsPerQueue( String testcaseIds ) throws DatabaseAccessException {

Map allStatistics = new HashMap();

String sqlLog = new SqlRequestFormatter().add("testcase ids", testcaseIds).format();

Connection connection = getConnection();

CallableStatement callableStatement = null;

ResultSet rs = null;

try {

callableStatement = connection.prepareCall("{ call sp_get_number_of_checkpoints_per_queue(?) }");

callableStatement.setString(1, testcaseIds);

rs = callableStatement.executeQuery();

int numberRecords = 0;

while (rs.next()) {

String name = rs.getString("name");

int queueNumbers = rs.getInt("numberOfQueue");

allStatistics.put(name, queueNumbers);

}

logQuerySuccess(sqlLog, "system statistics", numberRecords);

} catch (Exception e) {

throw new DatabaseAccessException("Error when " + sqlLog, e);

} finally {

DbUtils.closeResultSet(rs);

DbUtils.close(connection, callableStatement);

}

return allStatistics;

}

開發者ID:Axway,項目名稱:ats-framework,代碼行數:34,

示例7: testInterfaceImplementation

?點讚 2

?

import java.sql.Connection; //導入方法依賴的package包/類

private void testInterfaceImplementation(Connection connToCheck) throws Exception {

Method[] dbmdMethods = java.sql.DatabaseMetaData.class.getMethods();

// can't do this statically, as we return different

// implementations depending on JDBC version

DatabaseMetaData dbmd = connToCheck.getMetaData();

checkInterfaceImplemented(dbmdMethods, dbmd.getClass(), dbmd);

Statement stmtToCheck = connToCheck.createStatement();

checkInterfaceImplemented(java.sql.Statement.class.getMethods(), stmtToCheck.getClass(), stmtToCheck);

PreparedStatement pStmtToCheck = connToCheck.prepareStatement("SELECT 1");

ParameterMetaData paramMd = pStmtToCheck.getParameterMetaData();

checkInterfaceImplemented(java.sql.PreparedStatement.class.getMethods(), pStmtToCheck.getClass(), pStmtToCheck);

checkInterfaceImplemented(java.sql.ParameterMetaData.class.getMethods(), paramMd.getClass(), paramMd);

pStmtToCheck = ((com.mysql.jdbc.Connection) connToCheck).serverPrepareStatement("SELECT 1");

checkInterfaceImplemented(java.sql.PreparedStatement.class.getMethods(), pStmtToCheck.getClass(), pStmtToCheck);

ResultSet toCheckRs = connToCheck.createStatement().executeQuery("SELECT 1");

checkInterfaceImplemented(java.sql.ResultSet.class.getMethods(), toCheckRs.getClass(), toCheckRs);

toCheckRs = connToCheck.createStatement().executeQuery("SELECT 1");

checkInterfaceImplemented(java.sql.ResultSetMetaData.class.getMethods(), toCheckRs.getMetaData().getClass(), toCheckRs.getMetaData());

if (versionMeetsMinimum(5, 0, 0)) {

createProcedure("interfaceImpl", "(IN p1 INT)\nBEGIN\nSELECT 1;\nEND");

CallableStatement cstmt = connToCheck.prepareCall("{CALL interfaceImpl(?)}");

checkInterfaceImplemented(java.sql.CallableStatement.class.getMethods(), cstmt.getClass(), cstmt);

}

checkInterfaceImplemented(java.sql.Connection.class.getMethods(), connToCheck.getClass(), connToCheck);

}

開發者ID:rafallis,項目名稱:BibliotecaPS,代碼行數:37,

示例8: testBug28689

?點讚 2

?

import java.sql.Connection; //導入方法依賴的package包/類

/**

* Tests fix for BUG#28689 - CallableStatement.executeBatch() doesn't work

* when connection property "noAccessToProcedureBodies" has been set to

* "true".

*

* The fix involves changing the behavior of "noAccessToProcedureBodies", in

* that the driver will now report all paramters as "IN" paramters but allow

* callers to call registerOutParameter() on them.

*

* @throws Exception

*/

public void testBug28689() throws Exception {

if (!versionMeetsMinimum(5, 0)) {

return; // no stored procedures

}

createTable("testBug28689", "(" +

"`id` int(11) NOT NULL auto_increment,`usuario` varchar(255) default NULL,PRIMARY KEY (`id`))");

this.stmt.executeUpdate("INSERT INTO testBug28689 (usuario) VALUES ('AAAAAA')");

createProcedure("sp_testBug28689", "(tid INT)\nBEGIN\nUPDATE testBug28689 SET usuario = 'BBBBBB' WHERE id = tid;\nEND");

Connection noProcedureBodiesConn = getConnectionWithProps("noAccessToProcedureBodies=true");

CallableStatement cStmt = null;

try {

cStmt = noProcedureBodiesConn.prepareCall("{CALL sp_testBug28689(?)}");

cStmt.setInt(1, 1);

cStmt.addBatch();

cStmt.executeBatch();

assertEquals("BBBBBB", getSingleIndexedValueWithQuery(noProcedureBodiesConn, 1, "SELECT `usuario` FROM testBug28689 WHERE id=1"));

} finally {

if (cStmt != null) {

cStmt.close();

}

if (noProcedureBodiesConn != null) {

noProcedureBodiesConn.close();

}

}

}

開發者ID:JuanJoseFJ,項目名稱:ProyectoPacientes,代碼行數:45,

示例9: callFunction

?點讚 2

?

import java.sql.Connection; //導入方法依賴的package包/類

private void callFunction(CallableStatement cStmt, Connection c) throws SQLException {

cStmt = c.prepareCall("{? = CALL testbug61203fn(?)}");

cStmt.registerOutParameter(1, Types.INTEGER);

cStmt.setFloat(2, 2);

cStmt.execute();

assertEquals(2f, cStmt.getInt(1), .001);

}

開發者ID:JuanJoseFJ,項目名稱:ProyectoPacientes,代碼行數:8,

示例10: executeBatchedStoredProc

?點讚 2

?

import java.sql.Connection; //導入方法依賴的package包/類

private void executeBatchedStoredProc(Connection c) throws Exception {

this.stmt.executeUpdate("TRUNCATE TABLE testBatchTable");

CallableStatement storedProc = c.prepareCall("{call testBatch(?)}");

try {

int numBatches = 300;

for (int i = 0; i < numBatches; i++) {

storedProc.setInt(1, i + 1);

storedProc.addBatch();

}

int[] counts = storedProc.executeBatch();

assertEquals(numBatches, counts.length);

for (int i = 0; i < numBatches; i++) {

assertEquals(1, counts[i]);

}

this.rs = this.stmt.executeQuery("SELECT field1 FROM testBatchTable ORDER BY field1 ASC");

for (int i = 0; i < numBatches; i++) {

assertTrue(this.rs.next());

assertEquals(i + 1, this.rs.getInt(1));

}

} finally {

if (storedProc != null) {

storedProc.close();

}

}

}

開發者ID:Jugendhackt,項目名稱:OpenVertretung,代碼行數:35,

示例11: getTestcasesCount

?點讚 2

?

import java.sql.Connection; //導入方法依賴的package包/類

public int getTestcasesCount( String whereClause ) throws DatabaseAccessException {

String sqlLog = new SqlRequestFormatter().add("where", whereClause).format();

Connection connection = getConnection();

CallableStatement callableStatement = null;

ResultSet rs = null;

try {

callableStatement = connection.prepareCall("{ call sp_get_testcases_count(?) }");

callableStatement.setString(1, whereClause);

rs = callableStatement.executeQuery();

int testcasesCount = 0;

while (rs.next()) {

testcasesCount = rs.getInt("testcasesCount");

logQuerySuccess(sqlLog, "test cases", testcasesCount);

break;

}

return testcasesCount;

} catch (Exception e) {

throw new DatabaseAccessException("Error when " + sqlLog, e);

} finally {

DbUtils.closeResultSet(rs);

DbUtils.close(connection, callableStatement);

}

}

開發者ID:Axway,項目名稱:ats-framework,代碼行數:28,

示例12: testBug61150

?點讚 2

?

import java.sql.Connection; //導入方法依賴的package包/類

/**

* Tests fix for BUG#61150 - First call to SP

* fails with "No Database Selected"

* The workaround introduced in DatabaseMetaData.getCallStmtParameterTypes

* to fix the bug in server where SHOW CREATE PROCEDURE was not respecting

* lower-case table names is misbehaving when connection is not attached to

* database and on non-casesensitive OS.

*

* @throws Exception

* if the test fails.

*/

public void testBug61150() throws Exception {

NonRegisteringDriver driver = new NonRegisteringDriver();

Properties oldProps = driver.parseURL(BaseTestCase.dbUrl, null);

String host = driver.host(oldProps);

int port = driver.port(oldProps);

StringBuilder newUrlToTestNoDB = new StringBuilder("jdbc:mysql://");

if (host != null) {

newUrlToTestNoDB.append(host);

}

newUrlToTestNoDB.append(":").append(port).append("/");

Statement savedSt = this.stmt;

Properties props = getHostFreePropertiesFromTestsuiteUrl();

props.remove(NonRegisteringDriver.DBNAME_PROPERTY_KEY);

Connection conn1 = DriverManager.getConnection(newUrlToTestNoDB.toString(), props);

this.stmt = conn1.createStatement();

createDatabase("TST1");

createProcedure("TST1.PROC", "(x int, out y int)\nbegin\ndeclare z int;\nset z = x+1, y = z;\nend\n");

CallableStatement cStmt = null;

cStmt = conn1.prepareCall("{call `TST1`.`PROC`(?, ?)}");

cStmt.setInt(1, 5);

cStmt.registerOutParameter(2, Types.INTEGER);

cStmt.execute();

assertEquals(6, cStmt.getInt(2));

cStmt.clearParameters();

cStmt.close();

conn1.setCatalog("TST1");

cStmt = null;

cStmt = conn1.prepareCall("{call TST1.PROC(?, ?)}");

cStmt.setInt(1, 5);

cStmt.registerOutParameter(2, Types.INTEGER);

cStmt.execute();

assertEquals(6, cStmt.getInt(2));

cStmt.clearParameters();

cStmt.close();

conn1.setCatalog("mysql");

cStmt = null;

cStmt = conn1.prepareCall("{call `TST1`.`PROC`(?, ?)}");

cStmt.setInt(1, 5);

cStmt.registerOutParameter(2, Types.INTEGER);

cStmt.execute();

assertEquals(6, cStmt.getInt(2));

cStmt.clearParameters();

cStmt.close();

this.stmt = savedSt;

}

開發者ID:JuanJoseFJ,項目名稱:ProyectoPacientes,代碼行數:68,

示例13: populateSystemStatisticDefinition

?點讚 2

?

import java.sql.Connection; //導入方法依賴的package包/類

public int populateSystemStatisticDefinition(

String name,

String parentName,

String internalName,

String unit,

String params ) throws DatabaseAccessException {

if (parentName == null) {

parentName = "";

}

if (internalName == null) {

internalName = "";

}

CallableStatement callableStatement = null;

Connection con = null;

boolean useLocalConnection = false;

try {

if (connection == null || connection.isClosed()) {

// connection not set externally so use new connection only for

// this method invocation

useLocalConnection = true;

con = getConnection();

} else {

useLocalConnection = false;

con = connection;

}

final int statisticId = 6;

callableStatement = con.prepareCall("{ call sp_populate_system_statistic_definition(?, ?, ?, ?, ?, ?) }");

callableStatement.setString(1, parentName);

callableStatement.setString(2, internalName);

callableStatement.setString(3, name);

callableStatement.setString(4, unit);

callableStatement.setString(5, params);

callableStatement.registerOutParameter(statisticId, Types.INTEGER);

callableStatement.execute();

return callableStatement.getInt(statisticId);

} catch (Exception e) {

String errMsg = "Unable to populate statistic '" + name + "' with unit '" + unit

+ "' and params '" + params + "'";

throw new DatabaseAccessException(errMsg, e);

} finally {

DbUtils.closeStatement(callableStatement);

if (useLocalConnection) {

DbUtils.closeConnection(con);

}

}

}

開發者ID:Axway,項目名稱:ats-framework,代碼行數:52,

示例14: setUpClosedObjects

?點讚 2

?

import java.sql.Connection; //導入方法依賴的package包/類

@BeforeClass

public static void setUpClosedObjects() throws Exception {

// (Note: Can't use JdbcTest's connect(...) for this test class.)

final Connection connToClose =

new Driver().connect("jdbc:dremio:zk=local",

JdbcAssert.getDefaultProperties());

final Connection connToKeep =

new Driver().connect("jdbc:dremio:zk=local",

JdbcAssert.getDefaultProperties());

final Statement plainStmtToClose = connToKeep.createStatement();

final Statement plainStmtToKeep = connToKeep.createStatement();

final PreparedStatement preparedStmtToClose =

connToKeep.prepareStatement("VALUES 'PreparedStatement query'");

try {

connToKeep.prepareCall("VALUES 'CallableStatement query'");

fail("Test seems to be out of date. Was prepareCall(...) implemented?");

}

catch (SQLException | UnsupportedOperationException e) {

// Expected.

}

final ResultSet resultSetToCloseOnStmtToClose =

plainStmtToClose.executeQuery("VALUES 'plain Statement query'");

resultSetToCloseOnStmtToClose.next();

final ResultSet resultSetToCloseOnStmtToKeep =

plainStmtToKeep.executeQuery("VALUES 'plain Statement query'");

resultSetToCloseOnStmtToKeep.next();

final ResultSetMetaData rsmdForClosedStmt =

resultSetToCloseOnStmtToKeep.getMetaData();

final ResultSetMetaData rsmdForOpenStmt =

resultSetToCloseOnStmtToClose.getMetaData();

final DatabaseMetaData dbmd = connToClose.getMetaData();

connToClose.close();

plainStmtToClose.close();

preparedStmtToClose.close();

resultSetToCloseOnStmtToClose.close();

resultSetToCloseOnStmtToKeep.close();

closedConn = connToClose;

openConn = connToKeep;

closedPlainStmtOfOpenConn = plainStmtToClose;

closedPreparedStmtOfOpenConn = preparedStmtToClose;

closedResultSetOfClosedStmt = resultSetToCloseOnStmtToClose;

closedResultSetOfOpenStmt = resultSetToCloseOnStmtToKeep;

resultSetMetaDataOfClosedResultSet = rsmdForOpenStmt;

resultSetMetaDataOfClosedStmt = rsmdForClosedStmt;

databaseMetaDataOfClosedConn = dbmd;

// Self-check that member variables are set (and objects are in right open

// or closed state):

assertTrue("Test setup error", closedConn.isClosed());

assertFalse("Test setup error", openConn.isClosed());

assertTrue("Test setup error", closedPlainStmtOfOpenConn.isClosed());

assertTrue("Test setup error", closedPreparedStmtOfOpenConn.isClosed());

assertTrue("Test setup error", closedResultSetOfClosedStmt.isClosed());

assertTrue("Test setup error", closedResultSetOfOpenStmt.isClosed());

// (No ResultSetMetaData.isClosed() or DatabaseMetaData.isClosed():)

assertNotNull("Test setup error", resultSetMetaDataOfClosedResultSet);

assertNotNull("Test setup error", resultSetMetaDataOfClosedStmt);

assertNotNull("Test setup error", databaseMetaDataOfClosedConn);

}

示例15: createCallableStatement

?點讚 2

?

import java.sql.Connection; //導入方法依賴的package包/類

@Override

public CallableStatement createCallableStatement(Connection con) throws SQLException {

return con.prepareCall(this.callString);

}

開發者ID:lamsfoundation,項目名稱:lams,代碼行數:5,

示例16: testSPCache

?點讚 1

?

import java.sql.Connection; //導入方法依賴的package包/類

/**

* Tests parsing of stored procedures

*

* @throws Exception

* if an error occurs.

*/

public void testSPCache() throws Exception {

if (versionMeetsMinimum(5, 0)) {

CallableStatement storedProc = null;

createProcedure("testSpParse", "(IN FOO VARCHAR(15))\nBEGIN\nSELECT 1;\nend\n");

int numIterations = 10;

long startTime = System.currentTimeMillis();

for (int i = 0; i < numIterations; i++) {

storedProc = this.conn.prepareCall("{call testSpParse(?)}");

storedProc.close();

}

long elapsedTime = System.currentTimeMillis() - startTime;

System.out.println("Standard parsing/execution: " + elapsedTime + " ms");

storedProc = this.conn.prepareCall("{call testSpParse(?)}");

storedProc.setString(1, "abc");

this.rs = storedProc.executeQuery();

assertTrue(this.rs.next());

assertTrue(this.rs.getInt(1) == 1);

Properties props = new Properties();

props.setProperty("cacheCallableStmts", "true");

Connection cachedSpConn = getConnectionWithProps(props);

startTime = System.currentTimeMillis();

for (int i = 0; i < numIterations; i++) {

storedProc = cachedSpConn.prepareCall("{call testSpParse(?)}");

storedProc.close();

}

elapsedTime = System.currentTimeMillis() - startTime;

System.out.println("Cached parse stage: " + elapsedTime + " ms");

storedProc = cachedSpConn.prepareCall("{call testSpParse(?)}");

storedProc.setString(1, "abc");

this.rs = storedProc.executeQuery();

assertTrue(this.rs.next());

assertTrue(this.rs.getInt(1) == 1);

}

}

開發者ID:bragex,項目名稱:the-vigilantes,代碼行數:59,

注:本文中的java.sql.Connection.prepareCall方法示例整理自Github/MSDocs等源碼及文檔管理平臺,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。

總結

以上是生活随笔為你收集整理的java jdbc reparecall_Java Connection.prepareCall方法代碼示例的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。