Example usage for java.sql PreparedStatement close

List of usage examples for java.sql PreparedStatement close

Introduction

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

Prototype

void close() throws SQLException;

Source Link

Document

Releases this Statement object's database and JDBC resources immediately instead of waiting for this to happen when it is automatically closed.

Usage

From source file:com.mechanicshop.service.SearchServiceImpl.java

public String findFilter(String text) {
    String table = null;//from w  ww .jav a  2 s .co  m
    String sql = "SELECT No, Tag, Phone, Name, Vehicle, LicensePlate, Vin, InShop, OutShop, Status, "
            + "Mileage, Picked, Payment, Remarks, Rebuilder, Installer, FirstCheckBy, SecondCheckBy, "
            + "FirstCheckDate, SecondCheckDate, Media, ReferedBy, WarrantyLimit, Warranty FROM all_tables "
            + " WHERE (UPPER(Phone) LIKE " + "'%" + text + "%'" + " OR UPPER(Name) LIKE " + "'%" + text + "%'"
            + " OR UPPER(Vehicle) LIKE " + "'%" + text + "%'" + " OR UPPER(LicensePlate) " + "LIKE " + "'%"
            + text + "%'" + " OR UPPER(Vin) LIKE " + "'%" + text + "%'" + " OR UPPER(LicensePlate) LIKE " + "'%"
            + text + "%'" + " OR UPPER(Status) " + "LIKE " + "'%" + text + "%'" + " OR UPPER(Picked) LIKE "
            + "'%" + text + "%'" + " OR UPPER(Payment) LIKE " + "'%" + text + "%'" + " OR UPPER(Remarks) LIKE "
            + "'%" + text + "%'" + " OR UPPER(Rebuilder) " + "LIKE " + "'%" + text + "%'"
            + " OR UPPER(Installer) LIKE " + "'%" + text + "%'" + " OR UPPER(FirstCheckBy) LIKE " + "'%" + text
            + "%'" + " OR UPPER(SecondCheckBy) LIKE " + "'%" + text + "%'" + " " + "OR UPPER(Media) LIKE "
            + "'%" + text + "%'" + " OR UPPER(ReferedBy) LIKE " + "'%" + text + "%'"
            + " OR UPPER(WarrantyLimit) LIKE " + "'%" + text + "%'" + " OR " + "UPPER(Warranty) LIKE " + "'%"
            + text + "%'" + " OR UPPER(No) LIKE " + "'%" + text + "%'" + " OR UPPER(Tag) LIKE " + "'%" + text
            + "%'" + " OR UPPER(Mileage) LIKE " + "" + "'%" + text + "%'" + ")";

    Connection conn = null;

    try {
        conn = dataSource.getConnection();
        PreparedStatement ps = conn.prepareStatement(sql);

        ResultSet rs = ps.executeQuery();
        if (rs.next())
            table = rs.getString("Status");

        rs.close();
        ps.close();

    } catch (SQLException e) {
        throw new RuntimeException(e);
    } finally {
        if (conn != null) {
            try {
                conn.close();
            } catch (SQLException e) {
            }
        }
    }

    return table;
}

From source file:dk.netarkivet.harvester.datamodel.PostgreSQLSpecifics.java

/**
 * Get a temporary table for short-time use. The table should be disposed of
 * with dropTemporaryTable. The table has two columns domain_name
 * varchar(Constants.MAX_NAME_SIZE) config_name
 * varchar(Constants.MAX_NAME_SIZE)/* w  ww . j a  va2 s.  c  om*/
 *
 * @param c
 *            The DB connection to use.
 * @throws SQLException
 *             if there is a problem getting the table.
 * @return The name of the created table
 */
public String getJobConfigsTmpTable(Connection c) throws SQLException {
    ArgumentNotValid.checkNotNull(c, "Connection c");
    PreparedStatement s = c.prepareStatement(
            "CREATE TEMPORARY TABLE  " + "jobconfignames " + "( domain_name varchar(" + Constants.MAX_NAME_SIZE
                    + "), " + " config_name varchar(" + Constants.MAX_NAME_SIZE + ") ) ON COMMIT DROP");
    s.execute();
    s.close();
    return "jobconfignames";
}

From source file:oobbit.orm.LinkConnections.java

public int add(LinkConnection linkConnection) throws SQLException, NotValidLinkConnectionException {
    verifier.verify(linkConnection); // first verify then add if successful

    PreparedStatement statement = getConnection().prepareStatement(
            "INSERT INTO `oobbit`.`connections` (`source_link_id`, `destination_link_id`, `title`, `creator`, `create_time`, `edit_time`) VALUES (?, ?, ?, ?, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP);");
    statement.setInt(1, linkConnection.getSourceLinkId());
    statement.setInt(2, linkConnection.getDestinationLinkId());
    statement.setString(3, linkConnection.getTitle());
    statement.setInt(4, linkConnection.getCreator());

    statement.executeUpdate();//from  w w w .  j a  va2  s  .  c  o  m
    statement.close();

    return linkConnection.getSourceLinkId();
}

From source file:com.vigglet.util.ModelUtilBase.java

public int getTotalItems(int company) {
    int result = 0;

    try {//  www .j  a  v  a2  s  .  c o  m
        PreparedStatement stmt = getTotalItemsQuery();
        stmt.setInt(1, company);
        ResultSet rs = stmt.executeQuery();

        if (rs.next()) {
            result = rs.getInt("totalItems");
        }

        rs.close();
        stmt.close();
    } catch (SQLException ex) {
        logger.log(Level.SEVERE, null, ex);
    }

    return result;
}

From source file:data.AbstractRepository.java

public List<T> all() throws DataException {
    String query = new StringBuilder("SELECT * FROM ").append(DB_TABLE).append(";").toString();

    List<T> objects = new ArrayList<T>();
    try {/*from w  w w  . ja  v  a  2 s .  c  o  m*/
        Connection connection = DriverManager.getConnection(url, username, password);
        PreparedStatement statement = connection.prepareStatement(query);
        ResultSet result = statement.executeQuery();

        try {
            while (result.next()) {
                objects.add(setObject(result));
            }
        } finally {
            result.close();
            statement.close();
            connection.close();
        }

        return objects;
    } catch (SQLException e) {
        throw new DataException("Error retrieving all objects from " + DB_TABLE);
    }
}

From source file:mupomat.controller.ObradaKorisnik.java

public void postaviNovuLozinku(String lozinka, String korisnickoIme) {
    try {//w w w. j a  v  a2 s . c o m
        Connection veza = MySqlBazaPodataka.getConnection();

        PreparedStatement izraz = veza.prepareStatement("update korisnik set lozinka=? where korisnickoime=?");

        izraz.setString(1, DigestUtils.md5Hex(lozinka));
        izraz.setString(2, korisnickoIme);

        izraz.executeUpdate();

        izraz.close();

        veza.close();
    } catch (Exception e) {
        //  System.out.println(e.getMessage());
        e.printStackTrace();

    }
}

From source file:com.viettel.logistic.wms.dao.StockTransSerialDAO.java

public ResultDTO insertStockTransSerialConnection(StockTransSerialDTO stockTrans, Connection con) {
    ResultDTO result = new ResultDTO();
    String message = ParamUtils.SUCCESS;
    String key = stockTrans.getStockTransId() + "";
    StringBuilder sql = new StringBuilder();
    List params = new ArrayList();

    sql.append("INSERT INTO stock_trans_serial ");
    sql.append(" ( stock_trans_serial_id, stock_trans_id,"
            + "       stock_trans_detail_id, stock_trans_date, goods_id,"
            + "       goods_code, goods_name, goods_state, goods_unit_type," + "       from_serial, to_serial,"
            + "       amount_order, amount_real, bincode, barcode, " + "       create_datetime,"
            + "       cell_code ) ");
    sql.append(/*ww  w . j  a  va  2s .  c o  m*/
            " VALUES (STOCK_TRANS_SERIAL_SEQ.nextval,?,?,to_date(?,'dd/MM/yyyy hh24:mi:ss'),?,?,?,?,?,?,?,?,?,?,?,to_date(?,'dd/MM/yyyy hh24:mi:ss'),?) ");
    //
    //        params.add(stockTrans.getStockTransSerialId());
    params.add(stockTrans.getStockTransId());
    params.add(stockTrans.getStockTransDetailId());
    params.add(stockTrans.getStockTransDate());
    params.add(stockTrans.getGoodsId());
    params.add(stockTrans.getGoodsCode());
    params.add(stockTrans.getGoodsName());
    params.add(stockTrans.getGoodsState());
    params.add(stockTrans.getGoodsUnitType());
    params.add(stockTrans.getFromSerial());
    params.add(stockTrans.getToSerial());
    params.add(stockTrans.getAmountOrder());
    params.add(stockTrans.getAmountReal());
    params.add(stockTrans.getBincode());
    params.add(stockTrans.getBarcode());
    params.add(stockTrans.getCreateDatetime());
    params.add(stockTrans.getCellCode());
    //
    //tao statement bang preparestatement
    try {
        PreparedStatement stm = con.prepareStatement(sql.toString());

        for (int idx = 0; idx < params.size(); idx++) {
            stm.setString(idx + 1, DataUtil.nvl(params.get(idx), "").toString());
        }

        int num = stm.executeUpdate();
        stm.close();
        //
    } catch (Exception e) {
        e.printStackTrace();
        message = ParamUtils.FAIL;
        key = ParamUtils.SYSTEM_OR_DATA_ERROR;
    }
    //
    result.setKey(key);
    result.setMessage(message);
    return result;
    //

}

From source file:com.l2jfree.gameserver.datatables.ClanTable.java

public void deleteclanswars(int clanId1, int clanId2) {
    L2Clan clan1 = ClanTable.getInstance().getClan(clanId1);
    L2Clan clan2 = ClanTable.getInstance().getClan(clanId2);
    clan1.deleteEnemyClan(clan2);//from   w  w  w .j a v a  2 s .  c  o m
    clan2.deleteEnemyClan(clan1);
    clan1.broadcastClanStatus();
    clan2.broadcastClanStatus();

    Connection con = null;
    try {
        con = L2DatabaseFactory.getInstance().getConnection(con);
        PreparedStatement statement;
        statement = con.prepareStatement("DELETE FROM clan_wars WHERE clan1=? AND clan2=?");
        statement.setInt(1, clanId1);
        statement.setInt(2, clanId2);
        statement.execute();

        statement.close();
    } catch (Exception e) {
        _log.error("could not restore clans wars data:", e);
    } finally {
        L2DatabaseFactory.close(con);
    }

    SystemMessage msg = new SystemMessage(SystemMessageId.WAR_AGAINST_S1_HAS_STOPPED);
    msg.addString(clan2.getName());
    clan1.broadcastToOnlineMembers(msg);
    msg = new SystemMessage(SystemMessageId.CLAN_S1_HAS_DECIDED_TO_STOP);
    msg.addString(clan1.getName());
    clan2.broadcastToOnlineMembers(msg);
}

From source file:com.mechanicshop.service.SearchServiceImpl.java

@Override
public String getMedia1() {
    String sql = "SELECT DefaultMedia1 FROM parameters ";
    Connection conn = null;//from   www .  jav  a 2s  .c  o  m
    String media = null;
    try {
        conn = dataSource.getConnection();
        PreparedStatement ps = conn.prepareStatement(sql);

        ResultSet rs = ps.executeQuery();
        while (rs.next()) {
            media = rs.getString("DefaultMedia1");

        }

        rs.close();
        ps.close();

    } catch (SQLException e) {
        throw new RuntimeException(e);
    } finally {
        if (conn != null) {
            try {
                conn.close();
            } catch (SQLException e) {
            }
        }
    }

    return media;
}