Example usage for java.sql PreparedStatement setString

List of usage examples for java.sql PreparedStatement setString

Introduction

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

Prototype

void setString(int parameterIndex, String x) throws SQLException;

Source Link

Document

Sets the designated parameter to the given Java String value.

Usage

From source file:com.silverpeas.notation.model.RatingDAO.java

public static long deleteComponentRatings(Connection con, String componentInstanceId) throws SQLException {
    PreparedStatement prepStmt = con.prepareStatement(QUERY_DELETE_COMPONENT_RATINGS);
    try {/* w ww  .j av a2 s .  c  o  m*/
        prepStmt.setString(1, componentInstanceId);
        return prepStmt.executeUpdate();
    } finally {
        DBUtil.close(prepStmt);
    }
}

From source file:com.chaosinmotion.securechat.server.commands.RemoveDevice.java

public static boolean processRequest(Login.UserInfo userinfo, JSONObject requestParams)
        throws ClassNotFoundException, SQLException, IOException {
    String deviceid = requestParams.optString("deviceid");

    /*/* w w  w  .  j  a va 2 s .co m*/
     * Delete device. We only delete if it is also ours.
     */
    Connection c = null;
    PreparedStatement ps = null;
    ResultSet rs = null;

    try {
        c = Database.get();
        ps = c.prepareStatement("DELETE FROM Devices " + "WHERE userid = ? AND deviceuuid = ?");
        ps.setInt(1, userinfo.getUserID());
        ps.setString(2, deviceid);
        ps.execute();

        return true;
    } finally {
        if (rs != null)
            rs.close();
        if (ps != null)
            ps.close();
        if (c != null)
            c.close();
    }
}

From source file:com.sql.EmailAttachment.java

/**
 * Insert attachement into received email attachment database table.
 * //  w ww  . j  a v a  2s.c  om
 * @param EmailID Integer
 * @param fileName String
 */
public static void insertEmailAttachment(int EmailID, String fileName) {
    Connection conn = null;
    PreparedStatement ps = null;
    try {
        conn = DBConnection.connectToDB();
        String sql = "INSERT INTO EmailAttachment (" + "emailID, " + "fileName " + ") VALUES (" + "?, " + "?)";
        ps = conn.prepareStatement(sql);
        ps.setInt(1, EmailID);
        ps.setString(2, fileName);
        ps.executeUpdate();
    } catch (SQLException ex) {
        ExceptionHandler.Handle(ex);
    } finally {
        DbUtils.closeQuietly(conn);
        DbUtils.closeQuietly(ps);
    }
}

From source file:Emporium.Controle.ContrDestinatarioImporta.java

public static int inserir(int idCliente, int idDepartamento, String nome, String cpf_cnpj, String empresa,
        String cep, String endereco, String numero, String complemento, String bairro, String cidade, String uf,
        String email, String celular, String pais, String nomeBD, String tags) {
    Connection conn = Conexao.conectar(nomeBD);
    String sql = "INSERT INTO cliente_destinatario (idCliente, nome, cpf_cnpj, empresa, cep, endereco, numero, complemento, bairro, cidade, uf, email, celular, pais, tags, idDepartamento) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
    //System.out.println("inserir Destinatario -----------------\n"+sql+"\n---------------");

    try {/*  w  ww.ja v a 2 s .com*/
        PreparedStatement valores = conn.prepareStatement(sql, PreparedStatement.RETURN_GENERATED_KEYS);
        valores.setInt(1, idCliente);
        valores.setString(2, FormataString.removeSpecialChars(nome));
        valores.setString(3, cpf_cnpj);
        valores.setString(4, empresa);
        valores.setString(5, cep);
        valores.setString(6, FormataString.removeSpecialChars(endereco));
        valores.setString(7, numero);
        valores.setString(8, complemento);
        valores.setString(9, bairro);
        valores.setString(10, cidade);
        valores.setString(11, uf);
        valores.setString(12, email);
        valores.setString(13, celular);
        valores.setString(14, pais);
        valores.setString(15, tags);
        valores.setInt(16, idDepartamento);
        valores.executeUpdate();
        int autoIncrementKey = 0;
        ResultSet rs = valores.getGeneratedKeys();
        if (rs.next()) {
            autoIncrementKey = rs.getInt(1);
        }
        valores.close();
        return autoIncrementKey;
    } catch (SQLException e) {
        //System.out.println("ERRO > "+e);
        ContrErroLog.inserir("HOITO - ContrPreVendaDest.inserir", "SQLException", sql, e.toString());
        return 0;
    } finally {
        Conexao.desconectar(conn);
    }
}

From source file:com.wso2telco.dao.TransactionDAO.java

/**
 * Insert sub value./*from   www  .  j a  v a  2 s.co  m*/
 *
 * @param token the context id
 * @param sub   the status code
 * @throws Exception the exception
 */
public static void insertTokenScopeLog(String token, String sub) throws Exception {
    Connection conn = null;
    PreparedStatement ps = null;
    try {
        conn = DbUtil.getConnectDBConnection();
        String query = "INSERT INTO scope_log ( access_token,sub) VALUES " + "(? ,?);";
        ps = conn.prepareStatement(query);
        ps.setString(1, token);
        ps.setString(2, sub);
        ps.execute();
        log.debug("Sub value inserted successfully");
    } catch (SQLException e) {
        handleException("Error in inserting transaction log record : " + e.getMessage(), e);
    } finally {
        DbUtil.closeAllConnections(ps, conn, null);
    }
}

From source file:de.erdesignerng.dialect.msaccess.MSAccessFileFormat.java

private static int getTableCount(Connection aConnection, String aTableName) throws SQLException {

    String theColumnName = "theCount";
    short theResult = 0;
    String theSQL = "SELECT Count(MSysObjects.Id) AS " + theColumnName + " " + "FROM MSysObjects "
            + "WHERE (MSysObjects.Name LIKE ?);";

    PreparedStatement theStatement = aConnection.prepareStatement(theSQL);
    theStatement.setString(1, aTableName);

    ResultSet theIdentificationResult = theStatement.executeQuery();

    if (theIdentificationResult != null) {
        if (theIdentificationResult.next()) {
            theResult = theIdentificationResult.getShort(theColumnName);
        }/*from  ww w . ja  v  a 2 s .  c o m*/

        theIdentificationResult.close();
    }

    return theResult;

}

From source file:com.sql.CaseType.java

/**
 * Gathers a list of active case types for finding the proper section based 
 * on the case number./*from   w w  w  . j a  va 2s .c o m*/
 * 
 * @param section For which section the method is currently processing
 * @return List CaseTypeModel
 */
public static List<CaseTypeModel> getCaseTypesBySection(String section) {
    List<CaseTypeModel> list = new ArrayList();
    Connection conn = null;
    PreparedStatement ps = null;
    ResultSet rs = null;
    try {
        conn = DBConnection.connectToDB();
        String sql = "SELECT * FROM CaseType WHERE active = 1 AND section = ?";
        ps = conn.prepareStatement(sql);
        ps.setString(1, section);
        rs = ps.executeQuery();
        while (rs.next()) {
            CaseTypeModel item = new CaseTypeModel();
            item.setId(rs.getInt("id"));
            item.setActive(rs.getBoolean("active"));
            item.setSection(rs.getString("Section"));
            item.setCaseType(rs.getString("caseType"));
            item.setDescription(rs.getString("Description"));
            list.add(item);
        }
    } catch (SQLException ex) {
        ExceptionHandler.Handle(ex);
    } finally {
        DbUtils.closeQuietly(conn);
        DbUtils.closeQuietly(ps);
        DbUtils.closeQuietly(rs);
    }
    return list;
}

From source file:at.becast.youploader.account.Account.java

public static Account read(String name) throws IOException {
    PreparedStatement stmt;
    try {//from   w w w. jav a2  s . c o m
        stmt = c.prepareStatement("SELECT * FROM `accounts` WHERE `name`=? LIMIT 1");
        stmt.setString(1, name);
        ResultSet rs = stmt.executeQuery();
        ObjectMapper mapper = new ObjectMapper();
        List<Cookie> c = mapper.readValue(rs.getString("cookie"), new TypeReference<List<Cookie>>() {
        });
        int id = rs.getInt("id");
        String token = rs.getString("refresh_token");
        stmt.close();
        rs.close();
        return new Account(id, name, token, c);
    } catch (SQLException e) {
        LOG.error("Account read error!", e);
        return null;
    }
}

From source file:com.krawler.common.util.SchedulingUtilities.java

public static String getCmpHolidaydays(Connection conn, String companyId) throws ServiceException {
    String res = "";
    try {/*from  w  w  w.  ja v a 2  s.c o  m*/
        String qry = "SELECT holiday, description FROM companyholidays WHERE companyid = ?";
        PreparedStatement pstmt = conn.prepareStatement(qry);
        pstmt.setString(1, companyId);
        ResultSet rs = pstmt.executeQuery();
        KWLJsonConverter j = new KWLJsonConverter();
        res = j.GetJsonForGrid(rs);
    } catch (SQLException e) {
        throw ServiceException.FAILURE("SchedulingUtilities.getCmpHolidaydays : " + e.getMessage(), e);
    }
    return res;
}

From source file:com.keybox.manage.db.ProfileDB.java

/**
 * inserts new profile/*from  w  w  w .ja  v a  2 s  .  c  o  m*/
 *
 * @param profile profile object
 */
public static void insertProfile(Profile profile) {

    Connection con = null;
    try {
        con = DBUtils.getConn();
        PreparedStatement stmt = con.prepareStatement("insert into profiles (nm, desc) values (?,?)");
        stmt.setString(1, profile.getNm());
        stmt.setString(2, profile.getDesc());
        stmt.execute();
        DBUtils.closeStmt(stmt);

    } catch (Exception e) {
        log.error(e.toString(), e);
    } finally {
        DBUtils.closeConn(con);
    }
}