當前位置: 首頁>>代碼示例>>Java>>正文


Java PreparedStatement.isClosed方法代碼示例

本文整理匯總了Java中java.sql.PreparedStatement.isClosed方法的典型用法代碼示例。如果您正苦於以下問題:Java PreparedStatement.isClosed方法的具體用法?Java PreparedStatement.isClosed怎麽用?Java PreparedStatement.isClosed使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.sql.PreparedStatement的用法示例。


在下文中一共展示了PreparedStatement.isClosed方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: disbandAlliance

import java.sql.PreparedStatement; //導入方法依賴的package包/類
public void disbandAlliance(MapleClient c, int allianceId) {
    PreparedStatement ps = null;
    try {
        ps = DatabaseConnection.getConnection().prepareStatement("DELETE FROM `alliance` WHERE id = ?");
        ps.setInt(1, allianceId);
        ps.executeUpdate();
        ps.close();
        Server.getInstance().allianceMessage(c.getPlayer().getGuild().getAllianceId(), MaplePacketCreator.disbandAlliance(allianceId), -1, -1);
        Server.getInstance().disbandAlliance(allianceId);
    } catch (SQLException sqle) {
        sqle.printStackTrace();
    } finally {
        try {
            if (ps != null && !ps.isClosed()) {
                ps.close();
            }
        } catch (SQLException ex) {
        }
    }
}
 
開發者ID:NovaStory,項目名稱:AeroStory,代碼行數:21,代碼來源:NPCConversationManager.java

示例2: excluirProduto

import java.sql.PreparedStatement; //導入方法依賴的package包/類
public static void excluirProduto(long id) throws SQLException, ClassNotFoundException {
    String sql = "DELETE FROM produto WHERE (produto.id=?)";

    Connection connection = null;

    PreparedStatement preparedStatement = null;
    try {
        connection = ConnectionUtils.getConnection();

        preparedStatement = connection.prepareStatement(sql);

        preparedStatement.setLong(1, id);

        preparedStatement.execute();
    } finally {
        if (preparedStatement != null && !preparedStatement.isClosed()) {
            preparedStatement.close();
        }
        if (connection != null && !connection.isClosed()) {
            connection.close();
        }
    }
}
 
開發者ID:OgumaJr,項目名稱:Entrega-Final,代碼行數:24,代碼來源:DaoProduto.java

示例3: closeConnection

import java.sql.PreparedStatement; //導入方法依賴的package包/類
public void closeConnection(Connection con, PreparedStatement ps, ResultSet rs) throws SQLException {
    if (con.isClosed() == false) {
        con.close();
    }
    if (ps.isClosed() == false) {
        ps.close();
    }
    if (rs.isClosed() == false) {
        rs.close();
    }
}
 
開發者ID:seyidkanan,項目名稱:my-diploma-work,代碼行數:12,代碼來源:ConnectionDB.java

示例4: hasLevel30Character

import java.sql.PreparedStatement; //導入方法依賴的package包/類
public boolean hasLevel30Character() {
    PreparedStatement ps = null;
    ResultSet rs = null;
    try {
        ps = DatabaseConnection.getConnection().prepareStatement("SELECT `level` FROM `characters` WHERE accountid = ?");
        ps.setInt(1, getPlayer().getAccountID());
        rs = ps.executeQuery();
        while (rs.next()) {
            if (rs.getInt("level") >= 30) {
                return true;
            }
        }
    } catch (SQLException sqle) {
        sqle.printStackTrace();
    } finally {
        try {
            if (ps != null && !ps.isClosed()) {
                ps.close();
            }
            if (rs != null && !rs.isClosed()) {
                rs.close();
            }
        } catch (SQLException ex) {
        }
    }
    return false;
}
 
開發者ID:NovaStory,項目名稱:AeroStory,代碼行數:28,代碼來源:PortalPlayerInteraction.java

示例5: updateMacs

import java.sql.PreparedStatement; //導入方法依賴的package包/類
public void updateMacs(String macData) {
    macs.addAll(Arrays.asList(macData.split(", ")));
    StringBuilder newMacData = new StringBuilder();
    Iterator<String> iter = macs.iterator();
    PreparedStatement ps = null;
    while (iter.hasNext()) {
        String cur = iter.next();
        newMacData.append(cur);
        if (iter.hasNext()) {
            newMacData.append(", ");
        }
    }
    try {
        ps = DatabaseConnection.getConnection().prepareStatement("UPDATE accounts SET macs = ? WHERE id = ?");
        ps.setString(1, newMacData.toString());
        ps.setInt(2, accId);
        ps.executeUpdate();
        ps.close();
    } catch (SQLException e) {
        e.printStackTrace();
    } finally {
        try {
            if (ps != null && !ps.isClosed()) {
                ps.close();
            }
        } catch (SQLException ex) {
        }
    }
}
 
開發者ID:NovaStory,項目名稱:AeroStory,代碼行數:30,代碼來源:MapleClient.java

示例6: inserirProduto

import java.sql.PreparedStatement; //導入方法依賴的package包/類
public static void inserirProduto(Produto produto) throws SQLException, ClassNotFoundException {
    String sql = "INSERT INTO produto (nome, descricao, "
            + "vl_compra, vl_venda, categoria, dt_cadastro)"
            + " VALUES (?, ?, ?, ?, ?, CURRENT_TIMESTAMP)";

    Connection connection = null;

    PreparedStatement preparedStatement = null;
    try {
        connection = ConnectionUtils.getConnection();

        preparedStatement = connection.prepareStatement(sql);

        preparedStatement.setString(1, produto.getNome());
        preparedStatement.setString(2, produto.getDescricao());
        preparedStatement.setBigDecimal(3, produto.getValorCompra());
        preparedStatement.setBigDecimal(4, produto.getValorVenda());
        preparedStatement.setString(5, produto.getCategoria());

        preparedStatement.execute();
    } finally {
        if (preparedStatement != null && !preparedStatement.isClosed()) {
            preparedStatement.close();
        }
        if (connection != null && !connection.isClosed()) {
            connection.close();
        }
    }
}
 
開發者ID:OgumaJr,項目名稱:Entrega-Final,代碼行數:30,代碼來源:DaoProduto.java

示例7: atualizarProduto

import java.sql.PreparedStatement; //導入方法依賴的package包/類
public static void atualizarProduto(Produto produto) throws SQLException, ClassNotFoundException {
    String sql = "UPDATE produto SET nome=?, descricao=?, vl_compra=?,"
            + " vl_venda=?, categoria=? WHERE (produto.id=?)";

    Connection connection = null;

    PreparedStatement preparedStatement = null;
    try {
        connection = ConnectionUtils.getConnection();

        preparedStatement = connection.prepareStatement(sql);

        preparedStatement.setString(1, produto.getNome());
        preparedStatement.setString(2, produto.getDescricao());
        preparedStatement.setBigDecimal(3, produto.getValorCompra());
        preparedStatement.setBigDecimal(4, produto.getValorVenda());
        preparedStatement.setString(5, produto.getCategoria());
        preparedStatement.setLong(6, produto.getId());

        preparedStatement.execute();
    } finally {
        if (preparedStatement != null && !preparedStatement.isClosed()) {
            preparedStatement.close();
        }
        if (connection != null && !connection.isClosed()) {
            connection.close();
        }
    }
}
 
開發者ID:OgumaJr,項目名稱:Entrega-Final,代碼行數:30,代碼來源:DaoProduto.java

示例8: ban

import java.sql.PreparedStatement; //導入方法依賴的package包/類
public static boolean ban(String id, String reason, boolean accountId) {
    PreparedStatement ps = null;
    try {
        Connection con = DatabaseConnection.getConnection();
        if (id.matches("/[0-9]{1,3}\\..*")) {
            ps = con.prepareStatement("INSERT INTO ipbans VALUES (DEFAULT, ?)");
            ps.setString(1, id);
            ps.executeUpdate();
            ps.close();
            return true;
        }
        if (accountId) {
            ps = con.prepareStatement("SELECT id FROM accounts WHERE name = ?");
        } else {
            ps = con.prepareStatement("SELECT accountid FROM characters WHERE name = ?");
        }

        boolean ret = false;
        ps.setString(1, id);
        try (ResultSet rs = ps.executeQuery()) {
            if (rs.next()) {
                try (PreparedStatement psb = DatabaseConnection.getConnection().prepareStatement("UPDATE accounts SET banned = 1, banreason = ? WHERE id = ?")) {
                    psb.setString(1, reason);
                    psb.setInt(2, rs.getInt(1));
                    psb.executeUpdate();
                }
                ret = true;
            }
        }
        ps.close();
        return ret;
    } catch (SQLException ex) {
    } finally {
        try {
            if (ps != null && !ps.isClosed()) {
                ps.close();
            }
        } catch (SQLException e) {
        }
    }
    return false;
}
 
開發者ID:NovaStory,項目名稱:AeroStory,代碼行數:43,代碼來源:MapleCharacter.java

示例9: ban

import java.sql.PreparedStatement; //導入方法依賴的package包/類
public static boolean ban(String id, String reason, boolean accountId) {
    PreparedStatement ps = null;
    try {
        Connection con = DatabaseConnection.getConnection();
        if (id.matches("/[0-9]{1,3}\\..*")) {
            ps = con.prepareStatement("INSERT INTO ipbans VALUES (DEFAULT, ?)");
            ps.setString(1, id);
            ps.executeUpdate();
            ps.close();
            return true;
        }
        if (accountId) {
            ps = con.prepareStatement("SELECT id FROM accounts WHERE name = ?");
        } else {
            ps = con.prepareStatement("SELECT accountid FROM characters WHERE name = ?");
        }
        boolean ret = false;
        ps.setString(1, id);
        try (ResultSet rs = ps.executeQuery()) {
            if (rs.next()) {
                try (PreparedStatement psb = DatabaseConnection.getConnection().prepareStatement("UPDATE accounts SET banned = 1, banreason = ? WHERE id = ?")) {
                    psb.setString(1, reason);
                    psb.setInt(2, rs.getInt(1));
                    psb.executeUpdate();
                }
                ret = true;
            }
        }
        ps.close();
        return ret;
    } catch (SQLException ex) {
    } finally {
        try {
            if (ps != null && !ps.isClosed()) {
                ps.close();
            }
        } catch (SQLException e) {
        }
    }
    return false;
}
 
開發者ID:ergothvs,項目名稱:Lucid2.0,代碼行數:42,代碼來源:MapleCharacter.java

示例10: procurarProduto

import java.sql.PreparedStatement; //導入方法依賴的package包/類
public static ArrayList<Produto> procurarProduto(String nomeProduto) throws SQLException, ClassNotFoundException {
    String sql = "SELECT * FROM produto WHERE (produto.nome LIKE(?))";

    ArrayList<Produto> listaProdutos = null;

    Connection connection = null;

    PreparedStatement preparedStatement = null;

    ResultSet result = null;
    try {
        connection = ConnectionUtils.getConnection();

        preparedStatement = connection.prepareStatement(sql);

        preparedStatement.setString(1, "%" + nomeProduto + "%");

        result = preparedStatement.executeQuery();

        while (result.next()) {
            if (listaProdutos == null) {
                listaProdutos = new ArrayList<>();
            }
            Produto produto = new Produto();
            produto.setId(result.getLong("id"));
            produto.setNome(result.getString("nome"));
            produto.setDescricao(result.getString("descricao"));
            produto.setValorCompra(result.getBigDecimal("vl_compra"));
            produto.setValorVenda(result.getBigDecimal("vl_venda"));
            produto.setCategoria(result.getString("categoria"));
            produto.setDtCadastro(result.getDate("dt_cadastro"));

            listaProdutos.add(produto);
        }
    } finally {
        if (result != null && !result.isClosed()) {
            result.close();
        }

        if (preparedStatement != null && !preparedStatement.isClosed()) {
            preparedStatement.close();
        }

        if (connection != null && !connection.isClosed()) {
            connection.close();
        }
    }

    return listaProdutos;
}
 
開發者ID:OgumaJr,項目名稱:Entrega-Final,代碼行數:51,代碼來源:DaoProduto.java

示例11: obterProduto

import java.sql.PreparedStatement; //導入方法依賴的package包/類
public static Produto obterProduto(long id) throws SQLException, ClassNotFoundException {
    String sql = "SELECT * FROM produto WHERE (produto.id=?)";

    Connection connection = null;

    PreparedStatement preparedStatement = null;

    ResultSet result = null;
    try {
        connection = ConnectionUtils.getConnection();

        preparedStatement = connection.prepareStatement(sql);

        preparedStatement.setLong(1, id);

        result = preparedStatement.executeQuery();
        if (result.next()) {
            Produto produto = new Produto();
            produto.setId(result.getLong("id"));
            produto.setNome(result.getString("nome"));
            produto.setDescricao(result.getString("descricao"));
            produto.setValorCompra(result.getBigDecimal("vl_compra"));
            produto.setValorVenda(result.getBigDecimal("vl_venda"));
            produto.setCategoria(result.getString("categoria"));
            produto.setDtCadastro(result.getDate("dt_cadastro"));

            return produto;
        }
    } finally {
        if (result != null && !result.isClosed()) {
            result.close();
        }
        if (preparedStatement != null && !preparedStatement.isClosed()) {
            preparedStatement.close();
        }
        if (connection != null && !connection.isClosed()) {
            connection.close();
        }
    }

    return null;
}
 
開發者ID:OgumaJr,項目名稱:Entrega-Final,代碼行數:43,代碼來源:DaoProduto.java


注:本文中的java.sql.PreparedStatement.isClosed方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。