java.sql.Statement#setMaxFieldSize ( )源码实例Demo

下面列出了java.sql.Statement#setMaxFieldSize ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

@Override
public final void setMaxFieldSize(final int max) throws SQLException {
    if (getRoutedStatements().isEmpty()) {
        recordMethodInvocation(recordTargetClass, "setMaxFieldSize", new Class[] {int.class}, new Object[] {max});
        return;
    }
    for (Statement each : getRoutedStatements()) {
        each.setMaxFieldSize(max);
    }
}
 
源代码2 项目: gemfirexd-oss   文件: J2EEDataSourceTest.java
/**
Create a statement with modified State.
 */
private Statement createFloatStatementForStateChecking(
    int[] StatementExpectedValues, Connection conn)
throws SQLException {
    Statement s = internalCreateFloatStatementForStateChecking(conn);
    s.setCursorName("StokeNewington");
    s.setFetchDirection(ResultSet.FETCH_REVERSE);
    s.setFetchSize(444);
    s.setMaxFieldSize(713);
    s.setMaxRows(19);

    // Create
    assertStatementState(null, StatementExpectedValues, s);
    return s;
}
 
源代码3 项目: gemfirexd-oss   文件: maxfieldsize.java
private static void testSort(Connection conn, Statement stmt)
	throws SQLException, java.io.UnsupportedEncodingException
{
	PreparedStatement insertPStmt;

	// Load up a 2nd table using streams where appropriate
	stmt.execute("create table tab2("+
								   "c0 int, " +
                                         "c1 char(100) for bit data,"+
                                         "c2 varchar(100) for bit data," +
                                         "c3 long varchar for bit data,"+
                                         "c4 char(100),"+ 
                                         "c5 varchar(100),"+
                                         "c6 long varchar)");

	// Populate the table
	insertPStmt = conn.prepareStatement(
					"insert into tab2 values (?, ?, ?, ?, ?, ?, ?)");
	for (int index = 0; index < 5000; index++)
	{
		insertPStmt.setInt(1, index);
           insertPStmt.setBytes(2, c1_value.getBytes("US-ASCII"));
           insertPStmt.setBytes(3, c2_value.getBytes("US-ASCII"));
           insertPStmt.setBytes(4, c3_value.getBytes("US-ASCII"));
           insertPStmt.setString(5, c4_value);
           insertPStmt.setString(6, c5_value);
           insertPStmt.setString(7, c6_value);
		insertPStmt.executeUpdate();
	}

	insertPStmt.close();

	// Do sort with maxFieldSize = 0
	doSort(stmt);

	// Set maxFieldSize to 24 and do another sort
	stmt.setMaxFieldSize(24);
	doSort(stmt);
}
 
源代码4 项目: gemfirexd-oss   文件: BrokeredStatement.java
void setStatementState(Statement oldStatement, Statement newStatement) throws SQLException {
	if (cursorName != null)
		newStatement.setCursorName(cursorName);
	if (escapeProcessing != null)
		newStatement.setEscapeProcessing(escapeProcessing.booleanValue());

	newStatement.setFetchDirection(oldStatement.getFetchDirection());
	newStatement.setFetchSize(oldStatement.getFetchSize());
	newStatement.setMaxFieldSize(oldStatement.getMaxFieldSize());
	newStatement.setMaxRows(oldStatement.getMaxRows());
	newStatement.setQueryTimeout(oldStatement.getQueryTimeout());
}
 
源代码5 项目: gemfirexd-oss   文件: J2EEDataSourceTest.java
/**
Create a statement with modified State.
 */
private Statement createFloatStatementForStateChecking(
    int[] StatementExpectedValues, Connection conn)
throws SQLException {
    Statement s = internalCreateFloatStatementForStateChecking(conn);
    s.setCursorName("StokeNewington");
    s.setFetchDirection(ResultSet.FETCH_REVERSE);
    s.setFetchSize(444);
    s.setMaxFieldSize(713);
    s.setMaxRows(19);

    // Create
    assertStatementState(null, StatementExpectedValues, s);
    return s;
}
 
源代码6 项目: gemfirexd-oss   文件: maxfieldsize.java
private static void testSort(Connection conn, Statement stmt)
	throws SQLException, java.io.UnsupportedEncodingException
{
	PreparedStatement insertPStmt;

	// Load up a 2nd table using streams where appropriate
	stmt.execute("create table tab2("+
								   "c0 int, " +
                                         "c1 char(100) for bit data,"+
                                         "c2 varchar(100) for bit data," +
                                         "c3 long varchar for bit data,"+
                                         "c4 char(100),"+ 
                                         "c5 varchar(100),"+
                                         "c6 long varchar)");

	// Populate the table
	insertPStmt = conn.prepareStatement(
					"insert into tab2 values (?, ?, ?, ?, ?, ?, ?)");
	for (int index = 0; index < 5000; index++)
	{
		insertPStmt.setInt(1, index);
           insertPStmt.setBytes(2, c1_value.getBytes("US-ASCII"));
           insertPStmt.setBytes(3, c2_value.getBytes("US-ASCII"));
           insertPStmt.setBytes(4, c3_value.getBytes("US-ASCII"));
           insertPStmt.setString(5, c4_value);
           insertPStmt.setString(6, c5_value);
           insertPStmt.setString(7, c6_value);
		insertPStmt.executeUpdate();
	}

	insertPStmt.close();

	// Do sort with maxFieldSize = 0
	doSort(stmt);

	// Set maxFieldSize to 24 and do another sort
	stmt.setMaxFieldSize(24);
	doSort(stmt);
}
 
源代码7 项目: gemfirexd-oss   文件: BrokeredStatement.java
void setStatementState(Statement oldStatement, Statement newStatement) throws SQLException {
	if (cursorName != null)
		newStatement.setCursorName(cursorName);
	if (escapeProcessing != null)
		newStatement.setEscapeProcessing(escapeProcessing.booleanValue());

	newStatement.setFetchDirection(oldStatement.getFetchDirection());
	newStatement.setFetchSize(oldStatement.getFetchSize());
	newStatement.setMaxFieldSize(oldStatement.getMaxFieldSize());
	newStatement.setMaxRows(oldStatement.getMaxRows());
	newStatement.setQueryTimeout(oldStatement.getQueryTimeout());
}
 
源代码8 项目: spliceengine   文件: BrokeredStatement.java
void setStatementState(Statement oldStatement, Statement newStatement) throws SQLException {
	if (cursorName != null)
		newStatement.setCursorName(cursorName);
	if (escapeProcessing != null)
		newStatement.setEscapeProcessing(escapeProcessing);

	newStatement.setFetchDirection(oldStatement.getFetchDirection());
	newStatement.setFetchSize(oldStatement.getFetchSize());
	newStatement.setMaxFieldSize(oldStatement.getMaxFieldSize());
	newStatement.setMaxRows(oldStatement.getMaxRows());
	newStatement.setQueryTimeout(oldStatement.getQueryTimeout());
}
 
源代码9 项目: spliceengine   文件: ResultSetStreamTest.java
/**
 * Tests that the max field size limit is handled correctly when accessing
 * values as streams. The limit should apply for VARCHAR, but not for CLOB.
 *
 * @throws IOException if something goes wrong
 * @throws SQLException if something goes wrong
 */
public void testSetMaxFieldSizeLarge()
        throws IOException, SQLException {
    // Insert test data.
    int id = 1;
    int clobSize = 2*1024*1024; // 2 MB
    int vcSize = 32672;
    int limit = 10;
    PreparedStatement ps = prepareStatement(
            "insert into setMaxFieldSize values (?,?,?)");
    ps.setInt(1, id);
    ps.setCharacterStream(2, new LoopingAlphabetReader(vcSize), vcSize);
    ps.setCharacterStream(3, new LoopingAlphabetReader(clobSize), clobSize);
    ps.executeUpdate();

    // Fetch data back with a limit.
    Statement stmt = createStatement();
    stmt.setMaxFieldSize(limit);
    ResultSet rs = stmt.executeQuery("select dVarchar, dClob from " +
            "setMaxFieldSize where id = " + id);
    assertTrue(rs.next());
    String vcStr = drainStringFromSource(rs.getCharacterStream(1));
    // Limit should apply to VARCHAR.
    assertEquals(limit, vcStr.length());
    // Limit should *not* apply to CLOB.
    String vsClob = drainStringFromSource(rs.getCharacterStream(2));
    assertEquals(clobSize, vsClob.length());
    rs.close();

    // Again, but without a limit.
    stmt = createStatement();
    rs = stmt.executeQuery("select dVarchar, dClob from " +
            "setMaxFieldSize where id = " + id);
    assertTrue(rs.next());
    vcStr = drainStringFromSource(rs.getCharacterStream(1));
    assertEquals(vcSize, vcStr.length());
    vsClob = drainStringFromSource(rs.getCharacterStream(2));
    assertEquals(clobSize, vsClob.length());
    rs.close();
}
 
源代码10 项目: spliceengine   文件: J2EEDataSourceTest.java
/**
 Create a statement with modified State.
 */
private Statement createFloatStatementForStateChecking(
        int[] StatementExpectedValues, Connection conn)
        throws SQLException {
    Statement s = internalCreateFloatStatementForStateChecking(conn);
    s.setCursorName("StokeNewington");
    s.setFetchDirection(ResultSet.FETCH_REVERSE);
    s.setFetchSize(444);
    s.setMaxFieldSize(713);
    s.setMaxRows(19);

    // Create
    assertStatementState(null, StatementExpectedValues, s);
    return s;
}
 
源代码11 项目: spliceengine   文件: maxfieldsize.java
private static void testSort(Connection conn, Statement stmt)
	throws SQLException, java.io.UnsupportedEncodingException
{
	PreparedStatement insertPStmt;

	// Load up a 2nd table using streams where appropriate
	stmt.execute("create table tab2("+
								   "c0 int, " +
                                         "c1 char(100) for bit data,"+
                                         "c2 varchar(100) for bit data," +
                                         "c3 long varchar for bit data,"+
                                         "c4 char(100),"+ 
                                         "c5 varchar(100),"+
                                         "c6 long varchar)");

	// Populate the table
	insertPStmt = conn.prepareStatement(
					"insert into tab2 values (?, ?, ?, ?, ?, ?, ?)");
	for (int index = 0; index < 5000; index++)
	{
		insertPStmt.setInt(1, index);
           insertPStmt.setBytes(2, c1_value.getBytes("US-ASCII"));
           insertPStmt.setBytes(3, c2_value.getBytes("US-ASCII"));
           insertPStmt.setBytes(4, c3_value.getBytes("US-ASCII"));
           insertPStmt.setString(5, c4_value);
           insertPStmt.setString(6, c5_value);
           insertPStmt.setString(7, c6_value);
		insertPStmt.executeUpdate();
	}

	insertPStmt.close();

	// Do sort with maxFieldSize = 0
	doSort(stmt);

	// Set maxFieldSize to 24 and do another sort
	stmt.setMaxFieldSize(24);
	doSort(stmt);
}
 
源代码12 项目: skywalking   文件: SWStatementTest.java
@Test
public void testPreparedStatementConfig() throws SQLException {
    Statement statement = swConnection.createStatement();
    statement.cancel();
    statement.getUpdateCount();
    statement.setFetchDirection(1);
    statement.getFetchDirection();
    statement.getResultSetConcurrency();
    statement.getResultSetType();
    statement.isClosed();
    statement.setPoolable(false);
    statement.isPoolable();
    statement.getWarnings();
    statement.clearWarnings();
    statement.setCursorName("test");
    statement.setMaxFieldSize(11);
    statement.getMaxFieldSize();
    statement.setMaxRows(10);
    statement.getMaxRows();
    statement.setEscapeProcessing(true);
    statement.setFetchSize(1);
    statement.getFetchSize();
    statement.setQueryTimeout(1);
    statement.getQueryTimeout();
    Connection connection = statement.getConnection();

    statement.execute("SELECT * FROM test");
    statement.getMoreResults();
    statement.getMoreResults(1);
    statement.getResultSetHoldability();
    statement.getResultSet();

    statement.close();
    verify(mysqlStatement).getUpdateCount();
    verify(mysqlStatement).getMoreResults();
    verify(mysqlStatement).setFetchDirection(anyInt());
    verify(mysqlStatement).getFetchDirection();
    verify(mysqlStatement).getResultSetType();
    verify(mysqlStatement).isClosed();
    verify(mysqlStatement).setPoolable(anyBoolean());
    verify(mysqlStatement).getWarnings();
    verify(mysqlStatement).clearWarnings();
    verify(mysqlStatement).setCursorName(anyString());
    verify(mysqlStatement).setMaxFieldSize(anyInt());
    verify(mysqlStatement).getMaxFieldSize();
    verify(mysqlStatement).setMaxRows(anyInt());
    verify(mysqlStatement).getMaxRows();
    verify(mysqlStatement).setEscapeProcessing(anyBoolean());
    verify(mysqlStatement).getResultSetConcurrency();
    verify(mysqlStatement).getResultSetConcurrency();
    verify(mysqlStatement).getResultSetType();
    verify(mysqlStatement).getMoreResults(anyInt());
    verify(mysqlStatement).setFetchSize(anyInt());
    verify(mysqlStatement).getFetchSize();
    verify(mysqlStatement).getQueryTimeout();
    verify(mysqlStatement).setQueryTimeout(anyInt());
    verify(mysqlStatement).getResultSet();
    assertThat(connection, CoreMatchers.<Connection>is(swConnection));

    TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
    List<AbstractTracingSpan> spans = SegmentHelper.getSpans(traceSegment);
    assertThat(spans.size(), is(1));
    assertDBSpan(spans.get(0), "Mysql/JDBI/Statement/execute", "SELECT * FROM test");
}