Example usage for java.sql PreparedStatement clearParameters

List of usage examples for java.sql PreparedStatement clearParameters

Introduction

In this page you can find the example usage for java.sql PreparedStatement clearParameters.

Prototype

void clearParameters() throws SQLException;

Source Link

Document

Clears the current parameter values immediately.

Usage

From source file:com.commander4j.db.JDBUserReport.java

public boolean updateUserID(String oldUserID, String newUserID) {
    boolean result = false;

    logger.debug("updateUserID oldUserID=[" + oldUserID + "] newUserId=[" + newUserID + "]");

    try {//from   www . j  ava2s  .c  om
        PreparedStatement stmtupdate;
        stmtupdate = Common.hostList.getHost(getHostID()).getConnection(getSessionID()).prepareStatement(
                Common.hostList.getHost(getHostID()).getSqlstatements().getSQL("JDBUserReport.updateUserID"));

        stmtupdate.setString(1, newUserID);
        stmtupdate.setString(2, oldUserID);

        stmtupdate.execute();
        stmtupdate.clearParameters();

        Common.hostList.getHost(getHostID()).getConnection(getSessionID()).commit();
        stmtupdate.close();
        result = true;

    } catch (SQLException e) {
        setErrorMessage(e.getMessage());
    }

    return result;
}

From source file:org.apereo.portal.groups.RDBMEntityGroupStore.java

private boolean containsEntity(IEntityGroup group, IGroupMember member) throws GroupsException {
    String groupKey = group.getLocalKey();
    String memberKey = member.getKey();
    Connection conn = RDBMServices.getConnection();
    try {/*from ww  w.  j a  v a  2 s . c o  m*/
        String sql = getCountAMemberEntitySql();
        PreparedStatement ps = conn.prepareStatement(sql);
        try {
            ps.clearParameters();
            ps.setString(1, groupKey);
            ps.setString(2, memberKey);
            if (log.isDebugEnabled())
                log.debug("RDBMEntityGroupStore.containsEntity(): " + ps + " (" + groupKey + ", " + memberKey
                        + ")");
            ResultSet rs = ps.executeQuery();
            try {
                return (rs.next()) && (rs.getInt(1) > 0);
            } finally {
                rs.close();
            }
        } finally {
            ps.close();
        }
    } catch (Exception e) {
        log.error("RDBMEntityGroupStore.containsEntity(): " + e);
        throw new GroupsException("Problem retrieving data from store: " + e);
    } finally {
        RDBMServices.releaseConnection(conn);
    }
}

From source file:org.apache.jmeter.protocol.jdbc.AbstractJDBCTestElement.java

private PreparedStatement getPreparedStatement(Connection conn, boolean callable) throws SQLException {
    Map<String, PreparedStatement> preparedStatementMap = perConnCache.get(conn);
    if (null == preparedStatementMap) {
        @SuppressWarnings("unchecked") // LRUMap is not generic
        Map<String, PreparedStatement> lruMap = new LRUMap(MAX_OPEN_PREPARED_STATEMENTS) {
            private static final long serialVersionUID = 1L;

            @Override/*from  www. j a  v a 2 s  . co  m*/
            protected boolean removeLRU(LinkEntry entry) {
                PreparedStatement preparedStatement = (PreparedStatement) entry.getValue();
                close(preparedStatement);
                return true;
            }
        };
        preparedStatementMap = Collections.<String, PreparedStatement>synchronizedMap(lruMap);
        // As a connection is held by only one thread, we cannot already have a 
        // preparedStatementMap put by another thread
        perConnCache.put(conn, preparedStatementMap);
    }
    PreparedStatement pstmt = preparedStatementMap.get(getQuery());
    if (null == pstmt) {
        if (callable) {
            pstmt = conn.prepareCall(getQuery());
        } else {
            pstmt = conn.prepareStatement(getQuery());
        }
        pstmt.setQueryTimeout(getIntegerQueryTimeout());
        // PreparedStatementMap is associated to one connection so 
        //  2 threads cannot use the same PreparedStatement map at the same time
        preparedStatementMap.put(getQuery(), pstmt);
    } else {
        int timeoutInS = getIntegerQueryTimeout();
        if (pstmt.getQueryTimeout() != timeoutInS) {
            pstmt.setQueryTimeout(getIntegerQueryTimeout());
        }
    }
    pstmt.clearParameters();
    return pstmt;
}

From source file:org.apereo.portal.groups.RDBMEntityGroupStore.java

private boolean containsGroup(IEntityGroup group, IEntityGroup member) throws GroupsException {
    String memberService = member.getServiceName().toString();
    String groupKey = group.getLocalKey();
    String memberKey = member.getLocalKey();
    Connection conn = RDBMServices.getConnection();
    try {//  ww w  .  j  ava 2 s .  com
        String sql = getCountAMemberGroupSql();
        PreparedStatement ps = conn.prepareStatement(sql);
        try {
            ps.clearParameters();
            ps.setString(1, groupKey);
            ps.setString(2, memberKey);
            ps.setString(3, memberService);
            if (log.isDebugEnabled())
                log.debug("RDBMEntityGroupStore.containsGroup(): " + ps + " (" + groupKey + ", " + memberKey
                        + ", " + memberService + ")");
            ResultSet rs = ps.executeQuery();
            try {
                return (rs.next()) && (rs.getInt(1) > 0);
            } finally {
                rs.close();
            }
        } finally {
            ps.close();
        }
    } catch (Exception e) {
        log.error("RDBMEntityGroupStore.containsGroup(): " + e);
        throw new GroupsException("Problem retrieving data from store: " + e);
    } finally {
        RDBMServices.releaseConnection(conn);
    }
}

From source file:org.sakaiproject.nakamura.lite.storage.jdbc.JDBCStorageClient.java

private Map<String, Object> internalGet(String keySpace, String columnFamily, String rid)
        throws StorageClientException {
    ResultSet body = null;/*from  w w w.j a  v a  2s .c o m*/
    Map<String, Object> result = Maps.newHashMap();
    PreparedStatement selectStringRow = null;
    try {
        selectStringRow = getStatement(keySpace, columnFamily, SQL_BLOCK_SELECT_ROW, rid, null);
        inc("A");
        selectStringRow.clearWarnings();
        selectStringRow.clearParameters();
        selectStringRow.setString(1, rid);
        body = selectStringRow.executeQuery();
        inc("B");
        if (body.next()) {
            Types.loadFromStream(rid, result, body.getBinaryStream(1), columnFamily);
        }
    } catch (SQLException e) {
        LOGGER.warn("Failed to perform get operation on  " + keySpace + ":" + columnFamily + ":" + rid, e);
        if (passivate != null) {
            LOGGER.warn("Was Pasivated ", passivate);
        }
        if (closed != null) {
            LOGGER.warn("Was Closed ", closed);
        }
        throw new StorageClientException(e.getMessage(), e);
    } catch (IOException e) {
        LOGGER.warn("Failed to perform get operation on  " + keySpace + ":" + columnFamily + ":" + rid, e);
        if (passivate != null) {
            LOGGER.warn("Was Pasivated ", passivate);
        }
        if (closed != null) {
            LOGGER.warn("Was Closed ", closed);
        }
        throw new StorageClientException(e.getMessage(), e);
    } finally {
        close(body, "B");
        close(selectStringRow, "A");
    }
    return result;
}

From source file:org.apache.jackrabbit.core.fs.db.DatabaseFileSystem.java

/**
 * Resets the given <code>PreparedStatement</code> by clearing the parameters
 * and warnings contained./* w  w  w  . ja va 2s .c om*/
 * <p/>
 * NOTE: This method MUST be called in a synchronized context as neither
 * this method nor the <code>PreparedStatement</code> instance on which it
 * operates are thread safe.
 *
 * @param stmt The <code>PreparedStatement</code> to reset. If
 *             <code>null</code> this method does nothing.
 */
protected void resetStatement(PreparedStatement stmt) {
    if (stmt != null) {
        try {
            stmt.clearParameters();
            stmt.clearWarnings();
        } catch (SQLException se) {
            log.error("failed resetting PreparedStatement", se);
        }
    }
}

From source file:uta.ak.CollectTweets.java

public void collectTweetsByKeyWords(String keyWords, String sinceDate, String untilDate, String tag) {
    try {//from w w  w.  j av a 2  s.co m

        ConfigurationBuilder cb = new ConfigurationBuilder();
        cb.setDebugEnabled(true).setOAuthConsumerKey("LuhVZOucqdHX6x0lcVgJO6QK3")
                .setOAuthConsumerSecret("6S7zbGLvHMXDMgRXq7jRIA6QmMpdI8i5IJNpnjlB55vpHpFMpj")
                .setOAuthAccessToken("861637891-kLunD37VRY8ipAK3TVOA0YKOKxeidliTqMtNb7wf")
                .setOAuthAccessTokenSecret("vcKDxs6qHnEE8fhIJr5ktDcTbPGql5o3cNtZuztZwPYl4");
        TwitterFactory tf = new TwitterFactory(cb.build());
        Twitter twitter = tf.getInstance();

        Connection con = null; //MYSQL
        Class.forName("com.mysql.jdbc.Driver").newInstance(); //MYSQL
        con = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/USTTMP", "root", "root.123"); //MYSQL
        System.out.println("connection yes");

        String insertSQL = "INSERT INTO c_rawtext(mme_lastupdate, mme_updater, title, text, tag, text_createdate) VALUES (NOW(), \"AK\", ?, ?, ?, ?)";
        PreparedStatement insertPS = con.prepareStatement(insertSQL);

        Calendar cal = Calendar.getInstance();
        cal.add(Calendar.DATE, 1);
        SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd");

        Query query = new Query(keyWords);
        query.setSince(sinceDate);
        query.setUntil(untilDate);
        query.setCount(100);
        query.setLang("en");

        QueryResult result = twitter.search(query);
        for (Status status : result.getTweets()) {
            //                    System.out.println("@" + status.getUser().getScreenName() +
            //                                       " | " + status.getCreatedAt().toString() +
            //                                       ":" + status.getText());
            //                    System.out.println("Inserting the record into the table...");

            String formattedDate = format1.format(status.getCreatedAt());

            insertPS.setString(1, status.getUser().getScreenName());
            insertPS.setString(2, status.getText());
            insertPS.setString(3, tag);
            insertPS.setString(4, formattedDate);
            insertPS.addBatch();
        }

        System.out.println("Start to insert records...");
        insertPS.clearParameters();
        int[] results = insertPS.executeBatch();

    } catch (Exception te) {
        te.printStackTrace();
        System.out.println("Failed: " + te.getMessage());
        System.exit(-1);
    }
}

From source file:org.apache.hadoop.yarn.server.applicationhistoryservice.metrics.timeline.PhoenixHBaseAccessor.java

/**
 * Save Metric aggregate records./*from   w w  w.java 2s  .c o  m*/
 *
 * @throws SQLException
 */
public void saveClusterAggregateRecords(Map<TimelineClusterMetric, MetricClusterAggregate> records)
        throws SQLException {

    if (records == null || records.isEmpty()) {
        LOG.debug("Empty aggregate records.");
        return;
    }

    long start = System.currentTimeMillis();

    Connection conn = getConnection();
    PreparedStatement stmt = null;
    try {
        stmt = conn.prepareStatement(UPSERT_CLUSTER_AGGREGATE_SQL);
        int rowCount = 0;

        for (Map.Entry<TimelineClusterMetric, MetricClusterAggregate> aggregateEntry : records.entrySet()) {
            TimelineClusterMetric clusterMetric = aggregateEntry.getKey();
            MetricClusterAggregate aggregate = aggregateEntry.getValue();

            if (LOG.isTraceEnabled()) {
                LOG.trace("clusterMetric = " + clusterMetric + ", " + "aggregate = " + aggregate);
            }

            rowCount++;
            stmt.clearParameters();
            stmt.setString(1, clusterMetric.getMetricName());
            stmt.setString(2, clusterMetric.getAppId());
            stmt.setString(3, clusterMetric.getInstanceId());
            stmt.setLong(4, clusterMetric.getTimestamp());
            stmt.setString(5, clusterMetric.getType());
            stmt.setDouble(6, aggregate.getSum());
            stmt.setInt(7, aggregate.getNumberOfHosts());
            stmt.setDouble(8, aggregate.getMax());
            stmt.setDouble(9, aggregate.getMin());

            try {
                stmt.executeUpdate();
            } catch (SQLException sql) {
                // we have no way to verify it works!!!
                LOG.error(sql);
            }

            if (rowCount >= PHOENIX_MAX_MUTATION_STATE_SIZE - 1) {
                conn.commit();
                rowCount = 0;
            }
        }

        conn.commit();

    } finally {
        if (stmt != null) {
            try {
                stmt.close();
            } catch (SQLException e) {
                // Ignore
            }
        }
        if (conn != null) {
            try {
                conn.close();
            } catch (SQLException sql) {
                // Ignore
            }
        }
    }
    long end = System.currentTimeMillis();
    if ((end - start) > 60000l) {
        LOG.info("Time to save: " + (end - start) + ", " + "thread = " + Thread.currentThread().getName());
    }
}

From source file:uk.co.swlines.cifreader.cif.CIFDatabase.java

public void insertScheduleBulk(ArrayList<CIFSchedule> r) throws LogicException {
    if (r.size() == 0)
        return;/*from  www. j  a va  2  s .c om*/

    try {
        final StringBuilder schedulesStatement = new StringBuilder(
                "INSERT INTO schedules_t (train_uid, date_from, date_to,"
                        + "runs_mo, runs_tu, runs_we, runs_th, runs_fr, runs_sa, runs_su, bank_hol, status, category, train_identity, headcode, "
                        + "service_code, portion_id, power_type, timing_load, speed, train_class, sleepers, reservations, catering_code, "
                        + "service_branding, stp_indicator, uic_code, atoc_code, ats_code, rsid, bus, train, ship, passenger, "
                        + "oc_b, oc_c, oc_d, oc_e, oc_g, oc_m, oc_p, oc_q, oc_r, oc_s, oc_y, oc_z) VALUES ");

        final StringBuilder locationsStatement = new StringBuilder(
                "INSERT INTO locations_t (id, location_order, location_type, "
                        + "tiploc_code, tiploc_instance, arrival, arrival_aftermidnight, public_arrival, public_arrival_aftermidnight, "
                        + "pass, pass_aftermidnight, departure, departure_aftermidnight, public_departure, public_departure_aftermidnight, "
                        + "platform, line, path, engineering_allowance, pathing_allowance, performance_allowance, public_call, "
                        + "actual_call, order_time, public_time, act_a, act_ae, act_bl, act_c, act_d, act_minusd, act_e, act_g, act_h, act_hh, act_k, act_kc, "
                        + "act_ke, act_kf, act_ks, act_l, act_n, act_op, act_or, act_pr, act_r, act_rm, act_rr, act_s, act_t, act_minust, act_tb, "
                        + "act_tf, act_ts, act_tw, act_u, act_minusu, act_w, act_x) VALUES ");

        final StringBuilder locationsChange = new StringBuilder(
                "INSERT INTO locations_change_t (schedule_id, location_id, category, "
                        + "train_identity, headcode, service_code, portion_id, power_type, timing_load, speed, train_class, sleepers, "
                        + "reservations, catering_code, service_branding, uic_code, rsid, oc_b, oc_c, oc_d, oc_e, oc_g, oc_m, oc_p, "
                        + "oc_q, oc_r, oc_s, oc_y, oc_z) VALUES " + createInsertPlaceholders(29));

        PreparedStatement stmtSchedules = getConnection().prepareStatement(
                schedulesStatement.append(createInsertPlaceholders(46)).toString(),
                Statement.RETURN_GENERATED_KEYS);

        PreparedStatement stmtLocChange = getConnection().prepareStatement(locationsChange.toString());

        int locationTotal = 0;

        for (CIFSchedule schedule : r) {
            int parameterIndex = 1;

            stmtSchedules.clearParameters();

            stmtSchedules.setString(parameterIndex++, schedule.getUid());

            stmtSchedules.setString(parameterIndex++, schedule.getDate_from());
            stmtSchedules.setString(parameterIndex++, schedule.getDate_to());
            stmtSchedules.setBoolean(parameterIndex++, schedule.isRuns_mo());
            stmtSchedules.setBoolean(parameterIndex++, schedule.isRuns_tu());
            stmtSchedules.setBoolean(parameterIndex++, schedule.isRuns_we());
            stmtSchedules.setBoolean(parameterIndex++, schedule.isRuns_th());
            stmtSchedules.setBoolean(parameterIndex++, schedule.isRuns_fr());
            stmtSchedules.setBoolean(parameterIndex++, schedule.isRuns_sa());
            stmtSchedules.setBoolean(parameterIndex++, schedule.isRuns_su());

            if (schedule.getBank_holiday() != ' ')
                stmtSchedules.setString(parameterIndex++, String.valueOf(schedule.getBank_holiday()));
            else
                stmtSchedules.setNull(parameterIndex++, java.sql.Types.CHAR);

            stmtSchedules.setString(parameterIndex++, String.valueOf(schedule.getStatus()).trim());
            stmtSchedules.setString(parameterIndex++, schedule.getCategory());
            stmtSchedules.setString(parameterIndex++, schedule.getTrain_identity());
            stmtSchedules.setString(parameterIndex++, schedule.getHeadcode());

            if (schedule.getService_code() != null)
                stmtSchedules.setInt(parameterIndex++, schedule.getService_code());
            else
                stmtSchedules.setNull(parameterIndex++, java.sql.Types.INTEGER);

            if (schedule.getPortion_id() != ' ')
                stmtSchedules.setString(parameterIndex++, String.valueOf(schedule.getPortion_id()));
            else
                stmtSchedules.setNull(parameterIndex++, java.sql.Types.CHAR);

            stmtSchedules.setString(parameterIndex++, schedule.getPower_type());
            stmtSchedules.setString(parameterIndex++, schedule.getTiming_load());
            stmtSchedules.setString(parameterIndex++, schedule.getSpeed());

            if (schedule.getTrain_class() != ' ')
                stmtSchedules.setString(parameterIndex++, String.valueOf(schedule.getTrain_class()));
            else
                stmtSchedules.setNull(parameterIndex++, java.sql.Types.CHAR);

            if (schedule.getSleepers() != ' ')
                stmtSchedules.setString(parameterIndex++, String.valueOf(schedule.getSleepers()));
            else
                stmtSchedules.setNull(parameterIndex++, java.sql.Types.CHAR);

            if (schedule.getReservations() != ' ')
                stmtSchedules.setString(parameterIndex++, String.valueOf(schedule.getReservations()));
            else
                stmtSchedules.setNull(parameterIndex++, java.sql.Types.CHAR);

            stmtSchedules.setString(parameterIndex++, schedule.getCatering_code());
            stmtSchedules.setString(parameterIndex++, schedule.getService_branding());
            stmtSchedules.setString(parameterIndex++, String.valueOf(schedule.getStp_indicator()).trim());
            stmtSchedules.setString(parameterIndex++, schedule.getUic_code());
            stmtSchedules.setString(parameterIndex++, schedule.getAtoc_code());
            stmtSchedules.setString(parameterIndex++, String.valueOf(schedule.getAts()).trim());
            stmtSchedules.setString(parameterIndex++, schedule.getRsid());

            stmtSchedules.setBoolean(parameterIndex++, schedule.isBus());
            stmtSchedules.setBoolean(parameterIndex++, schedule.isTrain());
            stmtSchedules.setBoolean(parameterIndex++, schedule.isShip());
            stmtSchedules.setBoolean(parameterIndex++, schedule.isPassenger());

            stmtSchedules.setBoolean(parameterIndex++, schedule.isOc_b());
            stmtSchedules.setBoolean(parameterIndex++, schedule.isOc_c());
            stmtSchedules.setBoolean(parameterIndex++, schedule.isOc_d());
            stmtSchedules.setBoolean(parameterIndex++, schedule.isOc_e());
            stmtSchedules.setBoolean(parameterIndex++, schedule.isOc_g());
            stmtSchedules.setBoolean(parameterIndex++, schedule.isOc_m());
            stmtSchedules.setBoolean(parameterIndex++, schedule.isOc_p());
            stmtSchedules.setBoolean(parameterIndex++, schedule.isOc_q());
            stmtSchedules.setBoolean(parameterIndex++, schedule.isOc_r());
            stmtSchedules.setBoolean(parameterIndex++, schedule.isOc_s());
            stmtSchedules.setBoolean(parameterIndex++, schedule.isOc_y());
            stmtSchedules.setBoolean(parameterIndex++, schedule.isOc_z());

            stmtSchedules.execute();

            locationTotal += schedule.getLocations().size();

            ResultSet rs = stmtSchedules.getGeneratedKeys();

            while (rs.next()) {
                schedule.setDatabaseId(rs.getInt(1));
            }

            rs.close();
        }

        stmtSchedules.close();

        int parameterIndex = 1;
        PreparedStatement stmtLocations = getConnection().prepareStatement(
                locationsStatement.append(createInsertPlaceholdersList(locationTotal, 59)).toString());

        for (CIFSchedule schedule : r) {
            int locationOrder = -1;
            Integer originDeparture = null, originPublicDeparture = null;

            CIFLocation origin = schedule.getLocations().get(0);
            if (origin instanceof CIFLocationOrigin) {
                originDeparture = ((CIFLocationOrigin) origin).getDeparture();
                originPublicDeparture = ((CIFLocationOrigin) origin).getPublic_departure();
            }

            if (originDeparture == null)
                throw new LogicException(schedule);

            for (CIFLocation location : schedule.getLocations()) {
                stmtLocations.setInt(parameterIndex++, schedule.getDatabaseId());
                stmtLocations.setInt(parameterIndex++, ++locationOrder);
                stmtLocations.setString(parameterIndex++, location.getLocationType());
                stmtLocations.setString(parameterIndex++, location.getTiploc());
                stmtLocations.setString(parameterIndex++, String.valueOf(location.getTiploc_instance()).trim());

                Integer orderTime = null;
                Integer publicTime = null;

                if (location instanceof CIFLocationArrival
                        && ((CIFLocationArrival) location).getArrival() != null) {
                    CIFLocationArrival locationArrival = (CIFLocationArrival) location;

                    stmtLocations.setInt(parameterIndex++, locationArrival.getArrival());
                    stmtLocations.setBoolean(parameterIndex++, locationArrival.getArrival() < originDeparture);

                    orderTime = locationArrival.getArrival();

                    if (locationArrival.getPublic_arrival() != null) {
                        stmtLocations.setInt(parameterIndex++, locationArrival.getPublic_arrival());
                        stmtLocations.setBoolean(parameterIndex++,
                                originPublicDeparture != null
                                        ? locationArrival.getPublic_arrival() < originPublicDeparture
                                        : null);

                        publicTime = locationArrival.getPublic_arrival();
                    } else {
                        stmtLocations.setNull(parameterIndex++, java.sql.Types.INTEGER);
                        stmtLocations.setNull(parameterIndex++, java.sql.Types.INTEGER);
                    }
                } else {
                    stmtLocations.setNull(parameterIndex++, java.sql.Types.INTEGER);
                    stmtLocations.setNull(parameterIndex++, java.sql.Types.INTEGER);
                    stmtLocations.setNull(parameterIndex++, java.sql.Types.INTEGER);
                    stmtLocations.setNull(parameterIndex++, java.sql.Types.INTEGER);
                }

                if (location instanceof CIFLocationIntermediate
                        && ((CIFLocationIntermediate) location).getPass() != null) {
                    CIFLocationIntermediate locationIntermediate = (CIFLocationIntermediate) location;

                    stmtLocations.setInt(parameterIndex++, locationIntermediate.getPass());
                    stmtLocations.setBoolean(parameterIndex++,
                            locationIntermediate.getPass() < originDeparture);

                    orderTime = locationIntermediate.getPass();
                } else {
                    stmtLocations.setNull(parameterIndex++, java.sql.Types.INTEGER);
                    stmtLocations.setNull(parameterIndex++, java.sql.Types.INTEGER);
                }

                if (location instanceof CIFLocationDepart
                        && ((CIFLocationDepart) location).getDeparture() != null) {
                    CIFLocationDepart locationDeparture = (CIFLocationDepart) location;

                    stmtLocations.setInt(parameterIndex++, locationDeparture.getDeparture());
                    stmtLocations.setBoolean(parameterIndex++,
                            locationDeparture.getDeparture() < originDeparture);

                    orderTime = locationDeparture.getDeparture();

                    if (locationDeparture.getPublic_departure() != null) {
                        stmtLocations.setInt(parameterIndex++, locationDeparture.getPublic_departure());
                        stmtLocations.setBoolean(parameterIndex++,
                                originPublicDeparture != null
                                        ? locationDeparture.getPublic_departure() < originPublicDeparture
                                        : null);

                        publicTime = locationDeparture.getPublic_departure();
                    } else {
                        stmtLocations.setNull(parameterIndex++, java.sql.Types.INTEGER);
                        stmtLocations.setNull(parameterIndex++, java.sql.Types.INTEGER);
                    }
                } else {
                    stmtLocations.setNull(parameterIndex++, java.sql.Types.INTEGER);
                    stmtLocations.setNull(parameterIndex++, java.sql.Types.INTEGER);
                    stmtLocations.setNull(parameterIndex++, java.sql.Types.INTEGER);
                    stmtLocations.setNull(parameterIndex++, java.sql.Types.INTEGER);
                }

                if (location.getPlatform().length() != 0)
                    stmtLocations.setString(parameterIndex++, location.getPlatform());
                else
                    stmtLocations.setNull(parameterIndex++, java.sql.Types.VARCHAR);

                if (location instanceof CIFLocationDepart
                        && ((CIFLocationDepart) location).getLine().length() != 0)
                    stmtLocations.setString(parameterIndex++, ((CIFLocationDepart) location).getLine());
                else
                    stmtLocations.setNull(parameterIndex++, java.sql.Types.VARCHAR);

                if (location instanceof CIFLocationArrival
                        && ((CIFLocationArrival) location).getPath().length() != 0)
                    stmtLocations.setString(parameterIndex++, ((CIFLocationArrival) location).getPath());
                else
                    stmtLocations.setNull(parameterIndex++, java.sql.Types.VARCHAR);

                if (location instanceof CIFLocationDepart) {
                    CIFLocationDepart locationDeparture = (CIFLocationDepart) location;

                    stmtLocations.setInt(parameterIndex++, locationDeparture.getAllowance_engineering());
                    stmtLocations.setInt(parameterIndex++, locationDeparture.getAllowance_pathing());
                    stmtLocations.setInt(parameterIndex++, locationDeparture.getAllowance_performance());
                } else {
                    stmtLocations.setInt(parameterIndex++, 0);
                    stmtLocations.setInt(parameterIndex++, 0);
                    stmtLocations.setInt(parameterIndex++, 0);
                }

                stmtLocations.setBoolean(parameterIndex++, location.isPublic_call());
                stmtLocations.setBoolean(parameterIndex++, location.isActual_call());

                //               stmtLocations.setInt(parameterIndex++, location.isActual_call() ? ( ? : ) : ((CIFLocationIntermediate) location).getPass());
                stmtLocations.setInt(parameterIndex++, orderTime);
                if (publicTime != null)
                    stmtLocations.setInt(parameterIndex++, publicTime);
                else
                    stmtLocations.setNull(parameterIndex++, java.sql.Types.INTEGER);

                stmtLocations.setBoolean(parameterIndex++, location.isAc_a());
                stmtLocations.setBoolean(parameterIndex++, location.isAc_ae());
                stmtLocations.setBoolean(parameterIndex++, location.isAc_bl());
                stmtLocations.setBoolean(parameterIndex++, location.isAc_c());
                stmtLocations.setBoolean(parameterIndex++, location.isAc_d());
                stmtLocations.setBoolean(parameterIndex++, location.isAc__d());
                stmtLocations.setBoolean(parameterIndex++, location.isAc_e());
                stmtLocations.setBoolean(parameterIndex++, location.isAc_g());
                stmtLocations.setBoolean(parameterIndex++, location.isAc_h());
                stmtLocations.setBoolean(parameterIndex++, location.isAc_hh());
                stmtLocations.setBoolean(parameterIndex++, location.isAc_k());
                stmtLocations.setBoolean(parameterIndex++, location.isAc_kc());
                stmtLocations.setBoolean(parameterIndex++, location.isAc_ke());
                stmtLocations.setBoolean(parameterIndex++, location.isAc_kf());
                stmtLocations.setBoolean(parameterIndex++, location.isAc_ks());
                stmtLocations.setBoolean(parameterIndex++, location.isAc_l());
                stmtLocations.setBoolean(parameterIndex++, location.isAc_n());
                stmtLocations.setBoolean(parameterIndex++, location.isAc_op());
                stmtLocations.setBoolean(parameterIndex++, location.isAc_or());
                stmtLocations.setBoolean(parameterIndex++, location.isAc_pr());
                stmtLocations.setBoolean(parameterIndex++, location.isAc_r());
                stmtLocations.setBoolean(parameterIndex++, location.isAc_rm());
                stmtLocations.setBoolean(parameterIndex++, location.isAc_rr());
                stmtLocations.setBoolean(parameterIndex++, location.isAc_s());
                stmtLocations.setBoolean(parameterIndex++, location.isAc_t());
                stmtLocations.setBoolean(parameterIndex++, location.isAc__t());
                stmtLocations.setBoolean(parameterIndex++, location.isAc_tb());
                stmtLocations.setBoolean(parameterIndex++, location.isAc_tf());
                stmtLocations.setBoolean(parameterIndex++, location.isAc_ts());
                stmtLocations.setBoolean(parameterIndex++, location.isAc_tw());
                stmtLocations.setBoolean(parameterIndex++, location.isAc_u());
                stmtLocations.setBoolean(parameterIndex++, location.isAc__u());
                stmtLocations.setBoolean(parameterIndex++, location.isAc_w());
                stmtLocations.setBoolean(parameterIndex++, location.isAc_x());

                if (location instanceof CIFLocationIntermediate) {
                    CIFLocationEnRouteChange change = ((CIFLocationIntermediate) location).getChangeRecord();

                    if (change != null) {
                        stmtLocChange.setInt(1, schedule.getDatabaseId());
                        stmtLocChange.setInt(2, locationOrder);
                        stmtLocChange.setString(3, change.getCategory());
                        stmtLocChange.setString(4, change.getTrain_identity());
                        stmtLocChange.setString(5, change.getHeadcode());
                        stmtLocChange.setString(6, change.getService_code());

                        if (change.getPortion_id() != ' ')
                            stmtLocChange.setString(7, String.valueOf(change.getPortion_id()));
                        else
                            stmtLocChange.setNull(7, java.sql.Types.CHAR);

                        stmtLocChange.setString(8, change.getPower_type());
                        stmtLocChange.setString(9, change.getTiming_load());
                        stmtLocChange.setString(10, change.getSpeed());

                        if (change.getTrain_class() != ' ')
                            stmtLocChange.setString(11, String.valueOf(change.getTrain_class()));
                        else
                            stmtLocChange.setNull(11, java.sql.Types.CHAR);

                        if (change.getSleeper() != ' ')
                            stmtLocChange.setString(12, String.valueOf(change.getSleeper()));
                        else
                            stmtLocChange.setNull(12, java.sql.Types.CHAR);

                        if (change.getReservations() != ' ')
                            stmtLocChange.setString(13, String.valueOf(change.getReservations()));
                        else
                            stmtLocChange.setNull(13, java.sql.Types.CHAR);

                        stmtLocChange.setString(14, change.getCatering_code());
                        stmtLocChange.setString(15, change.getService_branding());
                        stmtLocChange.setString(16, change.getUic());
                        stmtLocChange.setString(17, change.getRsid());

                        stmtLocChange.setBoolean(18, change.isOc_b());
                        stmtLocChange.setBoolean(19, change.isOc_c());
                        stmtLocChange.setBoolean(20, change.isOc_d());
                        stmtLocChange.setBoolean(21, change.isOc_e());
                        stmtLocChange.setBoolean(22, change.isOc_g());
                        stmtLocChange.setBoolean(23, change.isOc_m());
                        stmtLocChange.setBoolean(24, change.isOc_p());
                        stmtLocChange.setBoolean(25, change.isOc_q());
                        stmtLocChange.setBoolean(26, change.isOc_r());
                        stmtLocChange.setBoolean(27, change.isOc_s());
                        stmtLocChange.setBoolean(28, change.isOc_y());
                        stmtLocChange.setBoolean(29, change.isOc_z());

                        stmtLocChange.addBatch();
                    }
                }
            }
        }

        stmtLocChange.executeBatch();
        stmtLocations.execute();
        stmtLocations.close();
    } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        System.exit(1);
    }
}

From source file:com.commander4j.db.JDBUserReport.java

public boolean delete() {
    PreparedStatement stmtupdate;
    boolean result = false;
    setErrorMessage("");
    logger.debug("delete");

    try {/*from  w  w  w .ja  va2  s.c o m*/
        stmtupdate = Common.hostList.getHost(getHostID()).getConnection(getSessionID()).prepareStatement(
                Common.hostList.getHost(getHostID()).getSqlstatements().getSQL("JDBUserReport.delete"));
        stmtupdate.setString(1, getReportID());
        stmtupdate.execute();
        stmtupdate.clearParameters();
        Common.hostList.getHost(getHostID()).getConnection(getSessionID()).commit();

        stmtupdate.close();
        result = true;

    } catch (SQLException e) {
        setErrorMessage(e.getMessage());
    }

    return result;
}