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.app.dao.SearchQueryDAO.java

private static void _populateAddSearchQueryPreparedStatement(PreparedStatement preparedStatement,
        SearchQuery searchQuery) throws SQLException {

    preparedStatement.setInt(1, searchQuery.getUserId());
    preparedStatement.setString(2, searchQuery.getKeywords());
    preparedStatement.setString(3, searchQuery.getCategoryId());
    preparedStatement.setString(4, searchQuery.getSubcategoryId());
    preparedStatement.setBoolean(5, searchQuery.isSearchDescription());
    preparedStatement.setBoolean(6, searchQuery.isFreeShippingOnly());
    preparedStatement.setBoolean(7, searchQuery.isNewCondition());
    preparedStatement.setBoolean(8, searchQuery.isUsedCondition());
    preparedStatement.setBoolean(9, searchQuery.isUnspecifiedCondition());
    preparedStatement.setBoolean(10, searchQuery.isAuctionListing());
    preparedStatement.setBoolean(11, searchQuery.isFixedPriceListing());
    preparedStatement.setDouble(12, searchQuery.getMaxPrice());
    preparedStatement.setDouble(13, searchQuery.getMinPrice());
    preparedStatement.setString(14, searchQuery.getGlobalId());
    preparedStatement.setBoolean(15, searchQuery.isActive());
}

From source file:com.sql.RelatedCase.java

public static List<RelatedCaseModel> getRelatedCases(EmailOutModel eml) {
    List<RelatedCaseModel> list = new ArrayList();
    Connection conn = null;/*from  w  w w .j  ava2 s.c  o m*/
    PreparedStatement ps = null;
    ResultSet rs = null;
    try {
        int i = 0;
        conn = DBConnection.connectToDB();
        String sql = "SELECT * FROM RelatedCase WHERE LEN(relatedCaseNumber) = 16 " + " AND CaseYear = ? "
                + " AND CaseType = ? " + " AND CaseMonth = ? " + " AND CaseNumber = ? ";

        ps = conn.prepareStatement(sql);
        ps.setString(1, eml.getCaseYear());
        ps.setString(2, eml.getCaseType());
        ps.setString(3, eml.getCaseMonth());
        ps.setString(4, eml.getCaseNumber());

        rs = ps.executeQuery();
        while (rs.next()) {
            String[] relatedCase = rs.getString("relatedCaseNumber").split("-");

            if (relatedCase.length == 4) {
                RelatedCaseModel item = new RelatedCaseModel();
                item.setCaseYear(rs.getString("caseYear"));
                item.setCaseType(rs.getString("caseType"));
                item.setCaseMonth(rs.getString("caseMonth"));
                item.setCaseNumber(rs.getString("caseNumber"));
                item.setRelatedCaseYear(relatedCase[0]);
                item.setRelatedCaseType(relatedCase[1]);
                item.setRelatedCaseMonth(relatedCase[2]);
                item.setRelatedCaseNumber(relatedCase[3]);
                list.add(item);
            }
        }
    } catch (SQLException ex) {
        ExceptionHandler.Handle(ex);
    } finally {
        DbUtils.closeQuietly(conn);
        DbUtils.closeQuietly(ps);
        DbUtils.closeQuietly(rs);
    }
    return list;
}

From source file:FacultyAdvisement.StudentRepository.java

public static void create(DataSource ds, Student student) throws SQLException {
    String studentSQL = "INSERT INTO STUDENT(STUID, EMAIL, FIRSTNAME, LASTNAME, MAJORCODE, PHONE, ADVISED) "
            + "VALUES (?, ?, ?, ?, ?, ?, \'false\')";
    String userSQL = "INSERT INTO USERTABLE(PASSWORD, USERNAME, VERIFIED) VALUES (?, ?, ?)"; //haseeb was here

    String groupSQL = "INSERT INTO GROUPTABLE(GROUPNAME, USERNAME) VALUES (\'customergroup\', ?)";

    if (ds == null) {
        throw new SQLException("ds is null; Can't get data source");
    }//ww w  .j  a v  a 2s . c om

    Connection conn = ds.getConnection();

    if (conn == null) {
        throw new SQLException("conn is null; Can't get db connection");
    }

    try {

        //Here we execute three SQL statements
        //Student Information
        PreparedStatement sqlStatement = conn.prepareStatement(studentSQL);

        sqlStatement.setString(1, student.getId());
        sqlStatement.setString(2, student.getUsername());
        sqlStatement.setString(3, student.getFirstName());
        sqlStatement.setString(4, student.getLastName());
        sqlStatement.setString(5, student.getMajorCode());
        sqlStatement.setString(6, student.getPhoneNumber());

        sqlStatement.executeUpdate();

        //user credentials
        sqlStatement = conn.prepareStatement(userSQL);

        //Encrypt the pssword into SHA-256
        sqlStatement.setString(1, SHA256Encrypt.encrypt(student.getPassword()));

        sqlStatement.setString(2, student.getUsername());
        sqlStatement.setString(3, "false");
        sqlStatement.execute();

        //Group Table
        sqlStatement = conn.prepareStatement(groupSQL);
        sqlStatement.setString(1, student.getUsername());
        sqlStatement.execute();
    } finally {
        conn.close();
    }

}

From source file:com.wso2telco.util.DbUtil.java

public static void updateMultiplePasswordNoOfAttempts(String username, int attempts)
        throws SQLException, AuthenticatorException {

    Connection connection = null;
    PreparedStatement ps = null;

    String sql = "update `multiplepasswords` set  attempts=? where  username=?;";

    connection = getConnectDBConnection();

    ps = connection.prepareStatement(sql);

    ps.setInt(1, attempts);//from w  w w .j ava2 s .  c  o m
    ps.setString(2, username);
    ps.execute();

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

From source file:ca.qc.adinfo.rouge.leaderboard.db.LeaderboardDb.java

public static boolean createLeaderboard(DBManager dbManager, String key, String name) {

    Connection connection = null;
    PreparedStatement stmt = null;
    ResultSet rs = null;/* w w  w .  ja va  2 s.c o  m*/
    String sql = null;

    sql = "INSERT INTO rouge_leaderboards (`key`, `name`) VALUES (?, ?);";

    try {
        connection = dbManager.getConnection();
        stmt = connection.prepareStatement(sql);

        stmt.setString(1, key);
        stmt.setString(2, name);

        int ret = stmt.executeUpdate();

        return (ret > 0);

    } catch (SQLException e) {
        log.error(stmt);
        log.error(e);
        return false;

    } finally {

        DbUtils.closeQuietly(rs);
        DbUtils.closeQuietly(stmt);
        DbUtils.closeQuietly(connection);
    }
}

From source file:FacultyAdvisement.StudentRepository.java

public static void updatePassword(DataSource ds, String username, String password) throws SQLException {

    if (ds == null) {
        throw new SQLException("ds is null; Can't get data source");
    }/*from   w w  w.  jav a 2s . c o m*/

    Connection conn = ds.getConnection();

    if (conn == null) {
        throw new SQLException("conn is null; Can't get db connection");
    }

    String newPassword = SHA256Encrypt.encrypt(password);
    try {
        PreparedStatement ps = conn.prepareStatement("Update USERTABLE set PASSWORD=? where USERNAME=?");
        ps.setString(1, newPassword);
        ps.setString(2, username);

        ps.executeUpdate();

    } finally {
        conn.close();
    }
}

From source file:FacultyAdvisement.StudentRepository.java

public static void delete(DataSource ds, Student student) throws SQLException {
    Connection conn = ds.getConnection();
    if (conn == null) {
        throw new SQLException("conn is null; Can't get db connection");
    }//  ww w  .j  a  va 2  s.  com
    try {

        PreparedStatement ps;
        ps = conn.prepareStatement("Delete from STUDENT where EMAIL=?");
        ps.setString(1, student.getUsername());
        ps.executeUpdate();
        ps = conn.prepareStatement("Delete from USERTABLE where USERNAME=?");
        ps.setString(1, student.getUsername());
        ps.executeUpdate();
        ps = conn.prepareStatement("Delete from GROUPTABLE where USERNAME=?");
        ps.setString(1, student.getUsername());
        ps.executeUpdate();
    } finally {
        conn.close();
    }

    //students = (HashMap<String, StudentPOJO>) readAll(); // reload the updated info
}

From source file:com.sql.SECExceptions.java

/**
 * Gets a count of errors where the description text matches. This is to
 * eliminate the repeat of entries from the application looping
 *
 * @param description String//from  w  w  w. j  av a 2  s. c om
 * @return Integer count
 */
public static int getExistingException(String description) {
    int count = 0;
    Connection conn = null;
    PreparedStatement ps = null;
    ResultSet rs = null;
    try {
        conn = DBConnection.connectToDB();
        String sql = "SELECT COUNT(*) AS num FROM SECExceptions WHERE "
                + "timeOccurred >= CAST(CURRENT_TIMESTAMP AS DATE) AND exceptionDescrption LIKE ?";
        ps = conn.prepareStatement(sql);
        ps.setString(1, description + "%");

        rs = ps.executeQuery();
        while (rs.next()) {
            count = rs.getInt("num");
        }
    } catch (SQLException ex) {
        ExceptionHandler.Handle(ex);
    } finally {
        DbUtils.closeQuietly(conn);
        DbUtils.closeQuietly(ps);
        DbUtils.closeQuietly(rs);
    }
    return count;
}

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

/**
 * updates shared secret based on auth token
 *
 * @param secret    OTP shared secret/*from www . j  a  v a 2  s . c  o  m*/
 * @param authToken auth token
 */
public static void updateSharedSecret(String secret, String authToken) {

    Connection con = null;
    try {
        con = DBUtils.getConn();
        PreparedStatement stmt = con.prepareStatement("update users set otp_secret=? where auth_token=?");
        stmt.setString(1, EncryptionUtil.encrypt(secret));
        stmt.setString(2, authToken);
        stmt.execute();
        DBUtils.closeStmt(stmt);

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

}

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

public static String getNonWorkWeekdays(Connection conn, String projid) throws ServiceException {
    String retStr = null;//from ww w .  ja v a  2 s  .co m
    PreparedStatement pstmt = null;
    try {
        // week holidays
        pstmt = conn.prepareStatement("select day from proj_workweek where isholiday = true and projectid = ?");
        pstmt.setString(1, projid);
        ResultSet rs = pstmt.executeQuery();
        KWLJsonConverter kjs = new KWLJsonConverter();
        retStr = kjs.GetJsonForGrid(rs);
    } catch (SQLException e) {
        throw ServiceException.FAILURE("SchedulUtilities.getNonWorkWeekdays error", e);
    } finally {
        DbPool.closeStatement(pstmt);
    }
    return retStr;
}