diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DeleteIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DeleteIT.java index 505a5ae2d2d..d599e507df1 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DeleteIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DeleteIT.java @@ -800,9 +800,11 @@ private void testDeleteCount(boolean autoCommit, Integer limit) throws Exception allowServerSideMutations); try (Connection conn = DriverManager.getConnection(getUrl(), props)) { conn.createStatement().execute(ddl); - Statement stmt = conn.createStatement(); + String sqlStr = "UPSERT INTO " + tableName + " (pk1, v1) VALUES (?,'value')"; + PreparedStatement stmt = conn.prepareStatement(sqlStr); for (int i = 0; i < numRecords ; i++) { - stmt.executeUpdate("UPSERT INTO " + tableName + " (pk1, v1) VALUES (" + i + ",'value')"); + stmt.setInt(1, i); + stmt.executeUpdate(); } conn.commit(); conn.setAutoCommit(autoCommit); @@ -865,9 +867,11 @@ public void testDeleteShouldNotFailWhenTheRowsMoreThanMaxMutationSize() throws E try (Connection conn = DriverManager.getConnection(getUrl(), props)) { conn.createStatement().execute(ddl); conn.createStatement().execute(idx1); - Statement stmt = conn.createStatement(); + PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " + tableName + " VALUES (?, ?, 'value2')"); for(int i = 0; i < 20; i++) { - stmt.executeUpdate("UPSERT INTO " + tableName + " VALUES ("+i+",'value"+i+"', 'value2')"); + stmt.setInt(1, i); + stmt.setString(2, "value"+i); + stmt.executeUpdate(); if (i % 10 == 0) { conn.commit(); } diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DropTableIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DropTableIT.java index 823605d6004..bbee071b25e 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DropTableIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DropTableIT.java @@ -22,6 +22,7 @@ import java.sql.Connection; import java.sql.DriverManager; import java.sql.Statement; +import java.sql.PreparedStatement; import org.junit.Test; @@ -35,8 +36,9 @@ public void testRepeatedDropTable() throws Exception { final Statement stmt = conn.createStatement()) { assertFalse(stmt.execute(String.format("CREATE TABLE %s(pk varchar not null primary key)", tableName))); String dropTable = String.format("DROP TABLE IF EXISTS %s", tableName); + PreparedStatement pstmt = conn.prepareStatement(dropTable); for (int i = 0; i < 5; i++) { - assertFalse(stmt.execute(dropTable)); + assertFalse(pstmt.execute()); } } } diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpsertSelectAutoCommitIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpsertSelectAutoCommitIT.java index 8bd9ac35711..fcebae6a7dc 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpsertSelectAutoCommitIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpsertSelectAutoCommitIT.java @@ -241,11 +241,9 @@ public void testRowCountWithNoAutoCommitOnUpsertSelect() throws Exception { conn.createStatement().execute( "UPSERT INTO " + tableName + " VALUES (NEXT VALUE FOR "+ tableName + "_seq, 1)"); conn.commit(); + PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " + tableName + " SELECT NEXT VALUE FOR "+ tableName + "_seq, val FROM " + tableName); for (int i=0; i<6; i++) { - Statement stmt = conn.createStatement(); - int upsertCount = stmt.executeUpdate( - "UPSERT INTO " + tableName + " SELECT NEXT VALUE FOR "+ tableName + "_seq, val FROM " - + tableName); + int upsertCount = stmt.executeUpdate(); conn.commit(); assertEquals((int)Math.pow(2, i), upsertCount); } diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexRebuildIncrementDisableCountIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexRebuildIncrementDisableCountIT.java index 9b7ba9125f6..1ebffdefd6a 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexRebuildIncrementDisableCountIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexRebuildIncrementDisableCountIT.java @@ -24,6 +24,7 @@ import java.sql.DriverManager; import java.sql.SQLException; import java.sql.Statement; +import java.sql.PreparedStatement; import java.util.Collections; import java.util.List; import java.util.Map; @@ -168,11 +169,14 @@ static String getRandomOrgId(int maxOrgId) { private static void mutateRandomly(Connection conn, String tableName, int maxOrgId) { try { - Statement stmt = conn.createStatement(); + String sqlStr = "UPSERT INTO " + tableName + " VALUES(?, ?, ?, ?)"; + PreparedStatement stmt = conn.prepareStatement(sqlStr); for (int i = 0; i < 10000; i++) { - stmt.executeUpdate( - "UPSERT INTO " + tableName + " VALUES('" + getRandomOrgId(maxOrgId) + "'," + i - + "," + (i + 1) + "," + (i + 2) + ")"); + stmt.setString(1, getRandomOrgId(maxOrgId)); + stmt.setInt(2, i); + stmt.setInt(3, i + 1); + stmt.setInt(4, i + 2); + stmt.executeUpdate(); } conn.commit(); } catch (Exception e) { diff --git a/phoenix-core/src/it/java/org/apache/phoenix/tx/TxCheckpointIT.java b/phoenix-core/src/it/java/org/apache/phoenix/tx/TxCheckpointIT.java index 800dcc30b4d..a13dd4583a6 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/tx/TxCheckpointIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/tx/TxCheckpointIT.java @@ -28,6 +28,7 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; +import java.sql.PreparedStatement; import java.util.Arrays; import java.util.Collection; import java.util.Properties; @@ -99,14 +100,16 @@ public void testUpsertSelectDoesntSeeUpsertedData() throws Exception { props.setProperty(QueryServices.SCAN_RESULT_CHUNK_SIZE, Integer.toString(3)); Connection conn = getConnection(props); conn.setAutoCommit(true); - conn.createStatement().execute("CREATE SEQUENCE "+seqName); - conn.createStatement().execute("CREATE TABLE " + fullTableName + "(pk INTEGER PRIMARY KEY, val INTEGER)"+tableDDLOptions); - conn.createStatement().execute("CREATE "+(localIndex? "LOCAL " : "")+"INDEX " + indexName + " ON " + fullTableName + "(val)"); + Statement stmt = conn.createStatement(); + stmt.execute("CREATE SEQUENCE "+seqName); + stmt.execute("CREATE TABLE " + fullTableName + "(pk INTEGER PRIMARY KEY, val INTEGER)"+tableDDLOptions); + stmt.execute("CREATE "+(localIndex? "LOCAL " : "")+"INDEX " + indexName + " ON " + fullTableName + "(val)"); - conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES (NEXT VALUE FOR " + seqName + ",1)"); + stmt.execute("UPSERT INTO " + fullTableName + " VALUES (NEXT VALUE FOR " + seqName + ",1)"); + String sqlStr = "UPSERT INTO " + fullTableName + " SELECT NEXT VALUE FOR " + seqName + ", val FROM " + fullTableName; + PreparedStatement pstmt = conn.prepareStatement(sqlStr); for (int i=0; i<6; i++) { - Statement stmt = conn.createStatement(); - int upsertCount = stmt.executeUpdate("UPSERT INTO " + fullTableName + " SELECT NEXT VALUE FOR " + seqName + ", val FROM " + fullTableName); + int upsertCount = pstmt.executeUpdate(); assertEquals((int)Math.pow(2, i), upsertCount); } conn.close();