Example usage for java.sql PreparedStatement executeUpdate

List of usage examples for java.sql PreparedStatement executeUpdate

Introduction

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

Prototype

int executeUpdate() throws SQLException;

Source Link

Document

Executes the SQL statement in this PreparedStatement object, which must be an SQL Data Manipulation Language (DML) statement, such as INSERT, UPDATE or DELETE; or an SQL statement that returns nothing, such as a DDL statement.

Usage

From source file:dao.ContactAddShareMemberQuery.java

public void run(Connection conn, String ownerid, String destid) throws BaseDaoException {

    PreparedStatement query = null;
    String stmt = "insert into membercontacts values(" + ownerid + "," + destid + ")";
    try {//  ww w .j a  va2  s .  c  om
        query = conn.prepareStatement(stmt);
        query.executeUpdate();
    } catch (Exception e) {
        throw new BaseDaoException("Error occured while executing membercontacts addquery" + stmt, e);
    }
}

From source file:gobblin.data.management.retention.sql.SqlBasedRetentionPoc.java

private void execute(String query) throws SQLException {
    PreparedStatement insertStatement = connection.prepareStatement(query);
    insertStatement.executeUpdate();
}

From source file:dao.ActivateAccountQuery.java

public void run(Connection conn, String login, String aflag) throws BaseDaoException {

    PreparedStatement query = null;
    String stmt = "update hdlogin set aflag=" + aflag + " where login='" + login + "'";
    try {//from ww w  .jav  a  2s  . c o  m
        query = conn.prepareStatement(stmt);
        query.executeUpdate();
    } catch (Exception e) {
        throw new BaseDaoException("Error occured, executing update hdlogin " + stmt, e);
    }
}

From source file:dao.DirCopyDeleteQuery.java

/**
 * This method deletes directory/*  w  w  w .  j  a v  a  2 s . c  om*/
 * This method can be invoked only either the admins or the authors of this directory
 * @param conn the connection
 * @param cid the category id
 * @param ownerid the id of the owner
 * @exception BaseDaoException
 */
public void run(Connection conn, String directoryId, String loginid) throws BaseDaoException {

    try {
        PreparedStatement stmt = conn.prepareStatement("delete LOW_PRIORITY from dircopy where directoryid="
                + directoryId + " and loginid=" + loginid + " limit 1");
        stmt.executeUpdate();
    } catch (Exception e) {
        throw new BaseDaoException(
                "Error executing db query, delete from dircopy where directoryid=" + directoryId, e);
    }
}

From source file:dao.PersonalinfoUpdateQuery.java

public void run(Connection conn, String dob, String title, String ihave, String iwant, String industry,
        String company, String pwebsite, String cwebsite, String blogsite, String education, String city,
        String state, String country, String desc, String interests, String zipcode, int gender,
        String nickname, String designation, String bcity, String bstate, String bcountry, String bzipcode,
        String hphone, String cphone, String bphone, String yim, String aim, String msn, String icq,
        String loginid, String photoLabel, String docLabel, String street, String bstreet, String zone)
        throws BaseDaoException {

    byte[] mydesc = { ' ' };
    if (!RegexStrUtil.isNull(desc)) {
        mydesc = desc.getBytes();//www.ja  v a  2s  .c  o m
    }

    String stmt = "update usertab set dob='" + dob + "', title='" + title + "', ihave='" + ihave + "', iwant='"
            + iwant + "', industry='" + industry + "', company='" + company + "', pwebsite='" + pwebsite
            + "', cwebsite='" + cwebsite + "', blogsite='" + blogsite + "', education='" + education
            + "', city='" + city + "', state='" + state + "', country='" + country
            + "', description=?, interests='" + interests + "', zipcode='" + zipcode + "', designation='"
            + designation + "', gender=" + gender + ", nickname='" + nickname + "', bcity='" + bcity
            + "', bstate='" + bstate + "', bcountry='" + bcountry + "', bzipcode='" + bzipcode + "', hphone='"
            + hphone + "', bphone='" + bphone + "', cphone='" + cphone + "', yim='" + yim + "', aim='" + aim
            + "', msn='" + msn + "', icq='" + icq + "', photolabel='" + photoLabel + "', doclabel='" + docLabel
            + "', street='" + street + "', bstreet='" + bstreet + "', zone='" + zone + "' where loginid="
            + loginid + "";

    PreparedStatement query = null;
    try {
        query = conn.prepareStatement(stmt);
        query.setBytes(1, mydesc);
        query.executeUpdate();
    } catch (SQLException e) {
        throw new BaseDaoException("Error occured while executing update usertab, stmt = " + stmt, e);
    }
}

From source file:dao.ColTopicDeleteQuery.java

/**
  * Deletes a collabrum topic/* w w  w . j a  v a  2  s .  c  om*/
  * @param conn the connection
  * @param tidStr the threadid of this topic
  * @param memberid the memberid 
  */
public void run(Connection conn, String tidStr, String memberid) throws BaseDaoException {

    /*
       Integer tid = new Integer(tidStr);
       Long ownerid = new Long(memberid);
    */

    try {
        PreparedStatement stmt = conn.prepareStatement("delete LOW_PRIORITY from colltopics where tid=" + tidStr
                + " and ownerid=" + memberid + " limit 1");
        stmt.executeUpdate();
    } catch (Exception e) {
        logger.warn("Error occured while executing db query ", e);
        throw new BaseDaoException("Error occured while executing db query ", e);
    }
}

From source file:dao.CarryonTagsCaptionQuery.java

/**
 * This method is not called by spring./*from   w  w  w  .ja va  2s  .com*/
 *
 * @param conn the connection is passed to this method
 * @param caption the title of the blob
 * @param btitle the title of the blob
 * @param entryid 
 */
public void run(Connection conn, String title, String entryid, String loginid) throws BaseDaoException {

    /**
          *  Zoom is not applicable to files. Don't update zoom for file blobs
          **/
    try {
        PreparedStatement stmt = conn.prepareStatement("update carryontag set title='" + title
                + "' where entryid=" + entryid + " and ownerid=" + loginid + "");
        stmt.executeUpdate();
    } catch (Exception e) {
        String myquery = "update carryontag set title='" + title + "' where entryid=" + entryid
                + " and ownerid=" + loginid + "";
        throw new BaseDaoException("Error executing update CarryonTagsCaptionQuery " + myquery, e);
    }
}

From source file:dao.HdprofileAddExistingMemberQuery.java

public void run(Connection conn, String[] params) throws BaseDaoException {

    String informpm = params[0];/*from   w w w  . j  av  a  2s  .  c  om*/
    String informbb = params[1];
    String informfd = params[2];
    String loginid = params[3];

    try {
        PreparedStatement stmt = conn.prepareStatement("insert into hdprofile values (" + loginid + ", "
                + informpm + ", " + informbb + ", " + informfd + ")");
        stmt.executeUpdate();
    } catch (Exception e) {
        logger.warn("Error occured while executing hdprofileaddexistingmember query", e);
        throw new BaseDaoException("Error occured while executing hdprofileaddexistingmember query", e);
    }
}

From source file:dao.CollMembersDeleteQuery.java

/**
  * This method deletes a collabrum member given a collabrumid
  * @param conn - the connection/*from   w ww  . j  a  v a  2  s . c  o  m*/
  * @param collabrumId - the collabrumId
  * @param loginid - the loginid
  * @throws BaseDaoException - when error occurs
  */
public void run(Connection conn, String collabrumid, String loginid) throws BaseDaoException {

    try {
        PreparedStatement stmt = conn.prepareStatement("delete LOW_PRIORITY from collmembers where collabrumid="
                + collabrumid + " and loginid=" + loginid + " limit 1");
        stmt.executeUpdate();
    } catch (Exception e) {
        logger.warn("Error occured while executing db query ", e);
        throw new BaseDaoException("Error occured while executing db query ", e);
    }
}

From source file:login.login_servlet.java

public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    JSONObject arrayObj = new JSONObject();
    try {//from ww  w .j a v  a 2s. com

        LoginBean user = new LoginBean();
        user.setUsername(request.getParameter("EmailorUsername"));
        user.setPassword(request.getParameter("password"));
        int userID = 0;
        user = LoginDAO.login(user);
        System.out.println(user.isValid());
        if (user.isValid()) {
            String token = generateToken(20);
            userID = LoginDAO.getUserID(user);
            arrayObj.put("access_token", token);
            arrayObj.put("user_id", ((Integer) userID).toString());
            arrayObj.put("username", user.getUsername());
            arrayObj.put("status", "ok");
            System.out.println(token);
            System.out.println(((Integer) userID).toString());
            System.out.println(user.getUsername());

            String query = "INSERT INTO tokendata(user_id, token, create_time) VALUES ('" + userID + "','"
                    + token + "',NOW())";
            //to trace the process in console
            System.out.println("Your user name is " + user.getUsername());
            System.out.println("Your token is " + token);
            System.out.println("Query: " + query);
            Connection currentCon = null;
            currentCon = ConnectionManager.getConnection();
            try {
                //connect to database

                PreparedStatement ps = currentCon.prepareStatement(query);
                int i = ps.executeUpdate();
                System.out.println("TOKEN MASUK DATABASE");

            }

            catch (Exception ex) {
                System.out.println("Register failed: An Exception has occurred! " + ex);
            }

            finally {
                if (currentCon != null) {
                    try {
                        currentCon.close();
                    } catch (Exception e) {
                    }
                    currentCon = null;
                }
            }

            //RequestDispatcher rd=request.getRequestDispatcher("catalog.jsp");  
            //System.out.println("wkwk");
            //rd.forward(request,response);
            //System.out.println("wkwkwk");

        } else {
            arrayObj.put("status", "error");
        }

        response.setContentType("application/json:charset=UTF-8");
        response.getWriter().write(arrayObj.toString());
    } catch (Throwable theException) {
        System.out.println(theException);
    }
}