Java Code Examples for java.sql.PreparedStatement#cancel()

The following examples show how to use java.sql.PreparedStatement#cancel() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CloudSpannerPooledConnectionTest.java    From spanner-jdbc with MIT License 6 votes vote down vote up
@Test
public void testPrepareStatement() throws SQLException {
  CloudSpannerPooledConnection subject = createConnection();
  Connection connection = subject.getConnection();
  PreparedStatement statement = connection.prepareStatement("SELECT COL1, COL2, COL3 FROM FOO");
  assertFalse(statement.isClosed());

  Connection statementConnection = statement.getConnection();
  assertEquals(connection, statementConnection);

  assertEquals(ResultSet.TYPE_FORWARD_ONLY, statement.getResultSetType());
  try {
    statement.cancel();
  } catch (SQLException e) {
  }

  statement.close();
  assertTrue(statement.isClosed());
}
 
Example 2
Source File: SwPreparedStatementTest.java    From skywalking with Apache License 2.0 6 votes vote down vote up
@Test
public void testExecuteWithSQL() throws SQLException {
    PreparedStatement preparedStatement = swConnection.prepareStatement("UPDATE test SET  a = ?");
    preparedStatement.setString(1, "a");
    boolean updateCount = preparedStatement.execute("UPDATE test SET  a = 1");
    preparedStatement.cancel();
    preparedStatement.close();

    verify(mysqlPreparedStatement).execute(anyString());
    verify(mysqlPreparedStatement).close();
    TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
    List<AbstractTracingSpan> spans = SegmentHelper.getSpans(traceSegment);
    assertThat(spans.size(), is(1));
    assertDBSpan(spans.get(0), "Mysql/JDBI/PreparedStatement/execute", "UPDATE test SET  a = 1");

}
 
Example 3
Source File: SwPreparedStatementTest.java    From skywalking with Apache License 2.0 6 votes vote down vote up
@Test
public void testExecuteUpdate() throws SQLException {
    PreparedStatement preparedStatement = swConnection.prepareStatement("UPDATE test SET  a = ?");
    preparedStatement.setString(1, "a");
    int updateCount = preparedStatement.executeUpdate();
    preparedStatement.cancel();
    preparedStatement.close();

    verify(mysqlPreparedStatement).executeUpdate();
    verify(mysqlPreparedStatement).close();
    TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
    List<AbstractTracingSpan> spans = SegmentHelper.getSpans(traceSegment);
    assertThat(spans.size(), is(1));
    assertDBSpan(spans.get(0), "Mysql/JDBI/PreparedStatement/executeUpdate", "UPDATE test SET  a = ?");

}
 
Example 4
Source File: SwPreparedStatementTest.java    From skywalking with Apache License 2.0 6 votes vote down vote up
@Test
public void testUpdateSql() throws SQLException {
    PreparedStatement preparedStatement = swConnection.prepareStatement("UPDATE test SET  a = ?");

    int updateCount = preparedStatement.executeUpdate("UPDATE test SET  a = 1");
    preparedStatement.cancel();
    preparedStatement.close();

    verify(mysqlPreparedStatement).executeUpdate(anyString());
    verify(mysqlPreparedStatement).close();
    TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
    List<AbstractTracingSpan> spans = SegmentHelper.getSpans(traceSegment);
    assertThat(spans.size(), is(1));
    assertDBSpan(spans.get(0), "Mysql/JDBI/PreparedStatement/executeUpdate", "UPDATE test SET  a = 1");

}
 
Example 5
Source File: IgniteH2Indexing.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * Cancel prepared statement.
 *
 * @param stmt Statement.
 */
private static void cancelStatement(PreparedStatement stmt) {
    try {
        stmt.cancel();
    }
    catch (SQLException ignored) {
        // No-op.
    }
}
 
Example 6
Source File: SwPreparedStatementTest.java    From skywalking with Apache License 2.0 5 votes vote down vote up
@Test
public void testUpdateWithAutoGeneratedKey() throws SQLException {
    PreparedStatement preparedStatement = swConnection.prepareStatement("UPDATE test SET  a = ?");

    int updateCount = preparedStatement.executeUpdate("UPDATE test SET  a = 1", 1);
    preparedStatement.cancel();
    preparedStatement.close();

    verify(mysqlPreparedStatement).close();
    TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
    List<AbstractTracingSpan> spans = SegmentHelper.getSpans(traceSegment);
    assertThat(spans.size(), is(1));
    assertDBSpan(spans.get(0), "Mysql/JDBI/PreparedStatement/executeUpdate", "UPDATE test SET  a = 1");
}
 
Example 7
Source File: SwPreparedStatementTest.java    From skywalking with Apache License 2.0 5 votes vote down vote up
@Test
public void testUpdateWithIntColumnIndexes() throws SQLException {
    PreparedStatement preparedStatement = swConnection.prepareStatement("UPDATE test SET  a = ?");

    int updateCount = preparedStatement.executeUpdate("UPDATE test SET  a = 1", new int[] {1});
    preparedStatement.cancel();
    preparedStatement.close();

    verify(mysqlPreparedStatement).close();
    TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
    List<AbstractTracingSpan> spans = SegmentHelper.getSpans(traceSegment);
    assertThat(spans.size(), is(1));
    assertDBSpan(spans.get(0), "Mysql/JDBI/PreparedStatement/executeUpdate", "UPDATE test SET  a = 1");

}
 
Example 8
Source File: SwPreparedStatementTest.java    From skywalking with Apache License 2.0 5 votes vote down vote up
@Test
public void testUpdateWithStringColumnIndexes() throws SQLException {
    PreparedStatement preparedStatement = swConnection.prepareStatement("UPDATE test SET  a = ?");

    int updateCount = preparedStatement.executeUpdate("UPDATE test SET  a = 1", new String[] {"1"});
    preparedStatement.cancel();
    preparedStatement.close();

    verify(mysqlPreparedStatement).close();
    TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
    List<AbstractTracingSpan> spans = SegmentHelper.getSpans(traceSegment);
    assertThat(spans.size(), is(1));
    assertDBSpan(spans.get(0), "Mysql/JDBI/PreparedStatement/executeUpdate", "UPDATE test SET  a = 1");
}