private void createTaskIdAndStateIndex(final Connection conn, final String tableName) throws SQLException { String sql = "CREATE INDEX " + TASK_ID_STATE_INDEX + " ON " + tableName + " (`task_id`, `state`);"; try (PreparedStatement preparedStatement = conn.prepareStatement(sql)) { preparedStatement.execute(); } }
private static void deleteManualRules(Connection connection) throws SQLException { try (PreparedStatement statement = connection.prepareStatement("DELETE FROM rules WHERE rules.plugin_name='manual'")) { statement.execute(); // commit is useless on some databases connection.commit(); } }
/** * Default organization must never be deleted */ private static void truncateOrganizations(String tableName, Statement ddlStatement, Connection connection) throws SQLException { try (PreparedStatement preparedStatement = connection.prepareStatement("delete from organizations where kee <> ?")) { preparedStatement.setString(1, "default-organization"); preparedStatement.execute(); // commit is useless on some databases connection.commit(); } }
/** * @throws Exception If failed. */ @Test public void testString() throws Exception { stmt = conn.prepareStatement(SQL_PART + " where strVal is not distinct from ?"); stmt.setString(1, "str"); ResultSet rs = stmt.executeQuery(); int cnt = 0; while (rs.next()) { if (cnt == 0) assert rs.getInt("id") == 1; cnt++; } assert cnt == 1; stmt.setNull(1, VARCHAR); stmt.execute(); rs = stmt.getResultSet(); cnt = 0; while (rs.next()) { if (cnt == 0) assert rs.getInt("id") == 2; cnt++; } assert cnt == 1; }
connection = DriverManager.getConnection(url, user, pass); } catch (SQLException ex) { LOG.error("Driver loading or connection issue", ex); .prepareStatement(((StringObjectInspector) argumentOI[3]) .getPrimitiveJavaObject(arguments[3].get())); for (int i = 4; i < arguments.length; ++i) { ps.setObject(i - 3, poi.getPrimitiveJavaObject(arguments[i].get())); ps.execute(); ps.close(); result.set(0); } finally { try { connection.close(); } catch (Exception ex) { LOG.error("Underlying SQL exception during close", ex);
@Test public void testArrayUpsertDateWithNulls1() throws Exception { Connection conn = DriverManager.getConnection(getUrl()); String t9 = generateUniqueName(); conn.createStatement().execute("CREATE TABLE " + t9 + " ( k VARCHAR PRIMARY KEY, a DATE[])"); PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " + t9 + " VALUES('a',ARRAY[TO_DATE('2015-05-20 06:12:14.184'),null,TO_DATE('2015-05-20 06:12:14.184'),null])"); stmt.execute(); conn.commit(); ResultSet rs = conn.createStatement().executeQuery("Select a from " + t9 + " where k = 'a'"); rs.next(); Array array = conn.createArrayOf("DATE",new Date[]{new Date(1432102334184l),new Date(0l),new Date(1432102334184l),new Date(0l)}); assertEquals(rs.getArray(1),array); conn.close(); }
@Test public void testUpperCaseEncodingType() throws Exception { Connection conn = DriverManager.getConnection(getUrl()); String tableName = generateUniqueName(); String ddl = "CREATE TABLE " + tableName + " ( pk VARCHAR(10) NOT NULL CONSTRAINT PK PRIMARY KEY (pk))"; conn.createStatement().execute(ddl); PreparedStatement ps = conn.prepareStatement("UPSERT INTO " + tableName + " (pk) VALUES (?)"); ps.setString(1, "1"); ps.execute(); conn.commit(); ResultSet rs = conn.createStatement().executeQuery("SELECT * FROM " + tableName + " WHERE pk = ENCODE(1, 'BASE62')"); assertTrue(rs.next()); }
throws SQLException { init(conn); PreparedStatement prep = conn.prepareStatement("SELECT ID FROM " + SCHEMA + ".INDEXES WHERE SCHEMA=? AND TABLE=?"); prep.setString(1, schema); prep.setString(2, table); ResultSet rs = prep.executeQuery(); if (!rs.next()) { return; prep = conn.prepareStatement("DELETE FROM " + SCHEMA + ".INDEXES WHERE ID=?"); prep.setInt(1, indexId); prep.execute(); createOrDropTrigger(conn, schema, table, false); prep = conn.prepareStatement("DELETE FROM " + SCHEMA + ".ROWS WHERE INDEXID=? AND ROWNUM<10000"); while (true) { prep.setInt(1, indexId); int deleted = prep.executeUpdate(); if (deleted == 0) {
private long insertBootstrapStartRow(Connection connection, String db, String table, String whereClause, String clientID,Long totalRows) throws SQLException { LOGGER.info("inserting bootstrap start row"); String sql = "insert into `bootstrap` (database_name, table_name, where_clause, total_rows, client_id) values(?, ?, ?, ?, ?)"; PreparedStatement preparedStatement = connection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS); preparedStatement.setString(1, db); preparedStatement.setString(2, table); preparedStatement.setString(3, whereClause); preparedStatement.setLong(4, totalRows); preparedStatement.setString(5, clientID); preparedStatement.execute(); ResultSet generatedKeys = preparedStatement.getGeneratedKeys(); generatedKeys.next(); return generatedKeys.getLong(1); }
@Test public void restoreAutoCommitInitialStateOnUnexpectedError() throws Exception { when(connection.prepareStatement(anyString(), anyInt(), anyInt())).thenReturn(statement); when(statement.execute()).thenReturn(true); when(statement.getUpdateCount()).thenReturn(1); doThrow(new SQLException("infrastructure error")).when(connection).commit(); inOrder.verify(connection).prepareStatement("insert into something (id, name) values (?, ?)", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); inOrder.verify(statement).execute(); inOrder.verify(statement).getUpdateCount(); inOrder.verify(connection).commit();
try (Connection con = DriverManager.getConnection(mHiveURL, mHiveUserName, mHiveUserPassword)) { try (PreparedStatement dropTablePS = con.prepareStatement(sql)) { dropTablePS.execute(); try (PreparedStatement loadTablePS = con.prepareStatement(sql)) { loadTablePS.executeUpdate(); try (PreparedStatement describeTablePS = con.prepareStatement(sql)) { describeTablePS.execute(); reportWriter.println("Result should be \"You passed Hive test!\" "); reportWriter.println("Checker result is: "); while (resultSet.next()) { reportWriter.println(resultSet.getString(1) + resultSet.getString(2));
/** * Shuts down the HSQL database, i.e. persists all data, closes all connections * and unlocks the database for other processes. * * <p>The command sends the <b><tt>SHUTDOWN</tt></b> SQL command. */ public void shutdown() { try { connection.prepareStatement("shutdown").execute(); } catch (SQLException e) { logger.log(Level.FINE, "Could not shutdown the connection", e); } finally { try { connection.close(); } catch (SQLException e) { logger.log(Level.FINE, "Could not close the connection", e); } } }
private void initTableValues() throws SQLException { String url = getUrl() + ";" + PhoenixRuntime.CURRENT_SCN_ATTRIB + "=" + nextTimestamp(); Properties props = new Properties(TEST_PROPERTIES); Connection conn = DriverManager.getConnection(url, props); PreparedStatement stmt = conn.prepareStatement( "upsert into " + TABLE_NAME + " VALUES (?, ?)"); stmt.setString(1, new String("a1A")); stmt.setInt(2, 1); stmt.execute(); stmt.setString(1, new String("a1E")); stmt.setInt(2, 2); stmt.execute(); conn.commit(); conn.close(); }
final Connection c = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE", "system", "manager"); String plsql = "" + " declare " + cs.setString(1, "12345"); cs.registerOutParameter(2, Types.VARCHAR); cs.registerOutParameter(3, OracleTypes.CURSOR); cs.execute(); while (cursorResultSet.next ()) c.close();
deleteReference.setInt(1, vulnerabilityId); deleteReference.execute(); deleteSoftware.setInt(1, vulnerabilityId); deleteSoftware.execute(); insertVulnerability.execute(); try { rs = insertVulnerability.getGeneratedKeys(); rs.next(); vulnerabilityId = rs.getInt(1); } catch (SQLException ex) { insertReference.execute(); try { rs = selectCpeId.executeQuery(); if (rs.next()) { cpeProductId = rs.getInt(1); insertSoftware.execute(); } catch (SQLException ex) { if (ex.getMessage().contains("Duplicate entry")) {
private void changeAdmins(final Connection con, final String sql, final List<JID> admins) throws SQLException { if (!admins.isEmpty()) { try (final PreparedStatement pstmt = con.prepareStatement(sql)) { for (final JID jid : admins) { pstmt.setString(1, jid.getNode()); pstmt.execute(); } } } }
/** * Delete all testsuite-suite data from the database * * @throws SQLException */ public void deleteTestData() throws SQLException { Connection cn = null; try { cn = getDataSource().getConnection(); cn.setAutoCommit( false ); PreparedStatement pmt = cn.prepareStatement( "delete from GEOMTEST" ); if ( !pmt.execute() ) { int updateCount = pmt.getUpdateCount(); LOG.info( "Removing " + updateCount + " rows." ); } cn.commit(); pmt.close(); } finally { try { if ( cn != null ) { cn.close(); } } catch (SQLException e) { // nothing to do } } }
insertSql.delete(len - 1, len).append(")"); try (Connection connTarget = targetDS.getConnection(); PreparedStatement pstmt = connTarget.prepareStatement(insertSql.toString())) { connTarget.setAutoCommit(false); while (rs.next()) { pstmt.clearParameters(); + " WHERE "); appendCondition(dbMapping, deleteSql, values, rs); try (PreparedStatement pstmt2 = connTarget.prepareStatement(deleteSql.toString())) { int k = 1; for (Object val : values.values()) { pstmt2.setObject(k++, val); pstmt2.execute(); pstmt.execute(); if (logger.isTraceEnabled()) { logger.trace("Insert into target table, sql: {}", insertSql); connTarget.commit(); completed = true; connTarget.commit();
return counts; PreparedStatement stmt = connection.prepareStatement(query); boolean isresult = stmt.execute(); ResultSet rs; Iterator<String> iter = strs.iterator(); String ph = iter.next(); if (rs.next()) { counts.add(new Pair(ph, rs.getLong("count"))); } else