diff --git a/src/protocol/jdbc/src/main/java/org/apache/jmeter/protocol/jdbc/AbstractJDBCTestElement.java b/src/protocol/jdbc/src/main/java/org/apache/jmeter/protocol/jdbc/AbstractJDBCTestElement.java index c69b9f00362..0680cf52e7d 100644 --- a/src/protocol/jdbc/src/main/java/org/apache/jmeter/protocol/jdbc/AbstractJDBCTestElement.java +++ b/src/protocol/jdbc/src/main/java/org/apache/jmeter/protocol/jdbc/AbstractJDBCTestElement.java @@ -167,6 +167,7 @@ protected byte[] execute(Connection conn, SampleResult sample) throws SQLExcepti if (SELECT.equals(currentQueryType)) { try (Statement stmt = conn.createStatement()) { setQueryTimeout(stmt, getIntegerQueryTimeout()); + configureMaxRows(stmt); ResultSet rs = null; try { rs = stmt.executeQuery(getQuery()); @@ -198,6 +199,7 @@ protected byte[] execute(Connection conn, SampleResult sample) throws SQLExcepti } else if (PREPARED_SELECT.equals(currentQueryType)) { try (PreparedStatement pstmt = getPreparedStatement(conn)) { setArguments(pstmt); + configureMaxRows(pstmt); ResultSet rs = null; try { rs = pstmt.executeQuery(); @@ -236,7 +238,15 @@ protected byte[] execute(Connection conn, SampleResult sample) throws SQLExcepti } } + private void configureMaxRows(Statement stmt) throws SQLException { + int maxRows = getIntegerResultSetMaxRows(); + if (maxRows >= 0) { + stmt.setMaxRows(maxRows); + } + } + private String resultSetsToString(PreparedStatement pstmt, boolean result, int[] out) throws SQLException, UnsupportedEncodingException { + configureMaxRows(pstmt); StringBuilder sb = new StringBuilder(); int updateCount = 0; boolean currentResult = result; diff --git a/src/protocol/jdbc/src/main/java/org/apache/jmeter/protocol/jdbc/sampler/JDBCSampler.java b/src/protocol/jdbc/src/main/java/org/apache/jmeter/protocol/jdbc/sampler/JDBCSampler.java index db95cd76617..7c23db03a82 100644 --- a/src/protocol/jdbc/src/main/java/org/apache/jmeter/protocol/jdbc/sampler/JDBCSampler.java +++ b/src/protocol/jdbc/src/main/java/org/apache/jmeter/protocol/jdbc/sampler/JDBCSampler.java @@ -72,16 +72,17 @@ public SampleResult sample(Entry e) { Connection conn = null; try { - if (JOrphanUtils.isBlank(getDataSource())) { + String dataSource = getDataSource(); + if (JOrphanUtils.isBlank(dataSource)) { throw new IllegalArgumentException("Name for DataSoure must not be empty in " + getName()); } try { - conn = DataSourceElement.getConnection(getDataSource()); + conn = DataSourceElement.getConnection(dataSource); } finally { res.connectEnd(); } - res.setResponseHeaders(DataSourceElement.getConnectionInfo(getDataSource())); + res.setResponseHeaders(DataSourceElement.getConnectionInfo(dataSource)); res.setResponseData(execute(conn, res)); } catch (SQLException ex) { final String errCode = Integer.toString(ex.getErrorCode()); diff --git a/src/protocol/jdbc/src/test/kotlin/org/apache/jmeter/protocol/jdbc/sampler/JDBCSamplerTest.kt b/src/protocol/jdbc/src/test/kotlin/org/apache/jmeter/protocol/jdbc/sampler/JDBCSamplerTest.kt index 1ab034de974..7777d2ae5c4 100644 --- a/src/protocol/jdbc/src/test/kotlin/org/apache/jmeter/protocol/jdbc/sampler/JDBCSamplerTest.kt +++ b/src/protocol/jdbc/src/test/kotlin/org/apache/jmeter/protocol/jdbc/sampler/JDBCSamplerTest.kt @@ -80,6 +80,7 @@ class JDBCSamplerTest { val stmt = mockk { every { executeQuery(any()) } returns rs justRun { queryTimeout = any() } + justRun { maxRows = any() } justRun { close() } } val conn = mockk { @@ -90,11 +91,13 @@ class JDBCSamplerTest { } sut.query = "SELECT" + sut.resultSetMaxRows = "10" val response = sut.executeForTest(conn, sample) verifyOrder { conn.createStatement() stmt.queryTimeout = 0 + stmt.maxRows = 10 stmt.executeQuery(any()) sample.latencyEnd() // getStringFromResultSet diff --git a/xdocs/changes.xml b/xdocs/changes.xml index ef7546a9c2f..d07120f1553 100644 --- a/xdocs/changes.xml +++ b/xdocs/changes.xml @@ -83,6 +83,7 @@ Summary
  • 61656192The Constant Throughput Timer is throwing a NullPointerException when using variables (vars.get) in "Target Throughput"-field
  • 6162The Constant Timer is throwing a NullPointerException when using variables (vars.get) in "delay"-field
  • 6193Log errors happening while JMeter starts the test (previously, errors from TestStateListener.testStarted were not logged)
  • +
  • 6216Pass JDBCSampler.maxRows to Statement.setMaxRows so the driver does not fetch extra rows from the database
  • Non-functional changes