Example usage for java.sql PreparedStatement setDate

List of usage examples for java.sql PreparedStatement setDate

Introduction

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

Prototype

void setDate(int parameterIndex, java.sql.Date x) throws SQLException;

Source Link

Document

Sets the designated parameter to the given java.sql.Date value using the default time zone of the virtual machine that is running the application.

Usage

From source file:nl.ordina.bag.etl.dao.AbstractBAGDAO.java

@Override
public void update(final Ligplaats origineel, final Ligplaats mutation) throws DAOException {
    try {//  w  ww. j a  v a 2s. c  o m
        transactionTemplate.execute(new TransactionCallbackWithoutResult() {
            @Override
            protected void doInTransactionWithoutResult(TransactionStatus status) {
                jdbcTemplate.update(new PreparedStatementCreator() {
                    @Override
                    public PreparedStatement createPreparedStatement(Connection connection)
                            throws SQLException {
                        PreparedStatement ps = connection.prepareStatement("update bag_ligplaats set"
                                + " aanduiding_record_inactief = ?," + " aanduiding_record_correctie = ?,"
                                + " officieel = ?," + " ligplaats_status = ?," + " ligplaats_geometrie = ?,"
                                + " einddatum_tijdvak_geldigheid = ?," + " in_onderzoek = ?,"
                                + " bron_documentdatum = ?," + " bron_documentnummer = ?,"
                                + " bag_nummeraanduiding_id = ?" + " where bag_ligplaats_id = ?"
                                + " and aanduiding_record_correctie = ?"
                                + " and begindatum_tijdvak_geldigheid = ?");
                        ps.setInt(1, mutation.getAanduidingRecordInactief().ordinal());
                        ps.setLong(2, mutation.getAanduidingRecordCorrectie());
                        ps.setInt(3, mutation.getOfficieel().ordinal());
                        ps.setInt(4, mutation.getLigplaatsStatus().ordinal());
                        ps.setString(5, mutation.getLigplaatsGeometrie());
                        if (mutation.getEinddatumTijdvakGeldigheid() == null)
                            ps.setNull(6, Types.TIMESTAMP);
                        else
                            ps.setTimestamp(6,
                                    new Timestamp(mutation.getEinddatumTijdvakGeldigheid().getTime()));
                        ps.setInt(7, mutation.getInOnderzoek().ordinal());
                        ps.setDate(8, new Date(mutation.getDocumentdatum().getTime()));
                        ps.setString(9, mutation.getDocumentnummer());
                        ps.setLong(10, mutation.getHoofdAdres());
                        ps.setLong(11, origineel.getIdentificatie());
                        ps.setLong(12, origineel.getAanduidingRecordCorrectie());
                        ps.setTimestamp(13,
                                new Timestamp(origineel.getBegindatumTijdvakGeldigheid().getTime()));
                        return ps;
                    }
                });
                deleteNevenadressen(TypeAdresseerbaarObject.LIGPLAATS, origineel);
                insertNevenadressen(TypeAdresseerbaarObject.LIGPLAATS, mutation);
            }
        });
    } catch (DataAccessException e) {
        throw new DAOException("Error updating ligplaats: " + origineel.getIdentificatie(), e);
    }
}

From source file:nl.ordina.bag.etl.dao.AbstractBAGDAO.java

@Override
public void update(final Standplaats origineel, final Standplaats mutation) throws DAOException {
    try {//from  ww  w .  j a  v a 2  s  .  c  o  m
        transactionTemplate.execute(new TransactionCallbackWithoutResult() {
            @Override
            protected void doInTransactionWithoutResult(TransactionStatus status) {
                jdbcTemplate.update(new PreparedStatementCreator() {
                    @Override
                    public PreparedStatement createPreparedStatement(Connection connection)
                            throws SQLException {
                        PreparedStatement ps = connection.prepareStatement("update bag_standplaats set"
                                + " aanduiding_record_inactief = ?," + " aanduiding_record_correctie = ?,"
                                + " officieel = ?," + " standplaats_status = ?," + " standplaats_geometrie = ?,"
                                + " einddatum_tijdvak_geldigheid = ?," + " in_onderzoek = ?,"
                                + " bron_documentdatum = ?," + " bron_documentnummer = ?,"
                                + " bag_nummeraanduiding_id = ?" + " where bag_standplaats_id = ?"
                                + " and aanduiding_record_correctie = ?"
                                + " and begindatum_tijdvak_geldigheid = ?");
                        ps.setInt(1, mutation.getAanduidingRecordInactief().ordinal());
                        ps.setLong(2, mutation.getAanduidingRecordCorrectie());
                        ps.setInt(3, mutation.getOfficieel().ordinal());
                        ps.setInt(4, mutation.getStandplaatsStatus().ordinal());
                        ps.setString(5, mutation.getStandplaatsGeometrie());
                        if (mutation.getEinddatumTijdvakGeldigheid() == null)
                            ps.setNull(6, Types.TIMESTAMP);
                        else
                            ps.setTimestamp(6,
                                    new Timestamp(mutation.getEinddatumTijdvakGeldigheid().getTime()));
                        ps.setInt(7, mutation.getInOnderzoek().ordinal());
                        ps.setDate(8, new Date(mutation.getDocumentdatum().getTime()));
                        ps.setString(9, mutation.getDocumentnummer());
                        ps.setLong(10, mutation.getHoofdAdres());
                        ps.setLong(11, origineel.getIdentificatie());
                        ps.setLong(12, origineel.getAanduidingRecordCorrectie());
                        ps.setTimestamp(13,
                                new Timestamp(origineel.getBegindatumTijdvakGeldigheid().getTime()));
                        return ps;
                    }
                });
                deleteNevenadressen(TypeAdresseerbaarObject.STANDPLAATS, origineel);
                insertNevenadressen(TypeAdresseerbaarObject.STANDPLAATS, mutation);
            }
        });
    } catch (DataAccessException e) {
        throw new DAOException("Error updating standplaats: " + origineel.getIdentificatie(), e);
    }
}

From source file:edu.ku.brc.specify.conversion.BasicSQLUtils.java

/**
 * @param pStmt//from   w  w w  .j av a2  s  .  c om
 * @param type
 * @param data
 * @throws SQLException 
 */
public static void setData(final PreparedStatement pStmt, final int type, final int colInx, final Object data)
        throws SQLException {
    if (data == null) {
        pStmt.setObject(colInx, null);
        return;
    }

    boolean isStr = data instanceof String;
    switch (type) {
    case java.sql.Types.TINYINT:
    case java.sql.Types.SMALLINT:
    case java.sql.Types.INTEGER:
        if (isStr) {
            pStmt.setString(colInx, (String) data);
        } else {
            pStmt.setInt(colInx, (Integer) data);
        }
        break;

    case java.sql.Types.FLOAT:
        if (isStr) {
            pStmt.setString(colInx, (String) data);
        } else {
            pStmt.setFloat(colInx, (Float) data);
        }
        break;

    case java.sql.Types.VARCHAR:
    case java.sql.Types.CHAR:
    case java.sql.Types.LONGVARCHAR:
    case java.sql.Types.LONGNVARCHAR:
    case java.sql.Types.NCHAR:
        if (isStr) {
            pStmt.setString(colInx, (String) data);
        } else {
            pStmt.setString(colInx, (String) data);
        }
        break;

    case java.sql.Types.REAL:
    case java.sql.Types.DOUBLE:
        if (isStr) {
            pStmt.setString(colInx, (String) data);
        } else {
            pStmt.setDouble(colInx, (Double) data);
        }
        break;

    case java.sql.Types.DATE:
        if (isStr) {
            pStmt.setString(colInx, (String) data);
        } else {
            pStmt.setDate(colInx, (java.sql.Date) data);
        }
        break;

    case java.sql.Types.TIMESTAMP:
        if (isStr) {
            pStmt.setString(colInx, (String) data);
        } else {
            pStmt.setTimestamp(colInx, (Timestamp) data);
        }
        break;

    case java.sql.Types.BOOLEAN:
        if (isStr) {
            String val = (String) data;
            pStmt.setBoolean(colInx, !val.equalsIgnoreCase("true"));
        } else {
            pStmt.setBoolean(colInx, (Boolean) data);
        }
        break;

    case java.sql.Types.BIT:
        if (data instanceof Boolean) {
            pStmt.setBoolean(colInx, (Boolean) data);
        } else {
            pStmt.setBoolean(colInx, !(((Integer) data) == 0));
        }
        break;

    default:
        throw new RuntimeException(String.format("Missing case for SQL Type %d for Column: %d Data[%s]", type,
                colInx, data.getClass().getSimpleName()));
    }
}

From source file:nl.ordina.bag.etl.dao.AbstractBAGDAO.java

@Override
public void insert(final OpenbareRuimte openbareRuimte) throws DAOException {
    try {//  w  ww  .j  a v  a  2  s  . co m
        jdbcTemplate.update(new PreparedStatementCreator() {
            @Override
            public PreparedStatement createPreparedStatement(Connection connection) throws SQLException {
                PreparedStatement ps = connection.prepareStatement("insert into bag_openbare_ruimte ("
                        + "bag_openbare_ruimte_id," + "aanduiding_record_inactief,"
                        + "aanduiding_record_correctie," + "openbare_ruimte_naam," + "officieel,"
                        + "begindatum_tijdvak_geldigheid," + "einddatum_tijdvak_geldigheid," + "in_onderzoek,"
                        + "openbare_ruimte_type," + "bron_documentdatum," + "bron_documentnummer,"
                        + "openbareruimte_status," + "bag_woonplaats_id," + "verkorte_openbare_ruimte_naam"
                        + ") values (?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
                ps.setLong(1, openbareRuimte.getIdentificatie());
                ps.setInt(2, openbareRuimte.getAanduidingRecordInactief().ordinal());
                ps.setLong(3, openbareRuimte.getAanduidingRecordCorrectie());
                ps.setString(4, openbareRuimte.getOpenbareRuimteNaam());
                ps.setInt(5, openbareRuimte.getOfficieel().ordinal());
                ps.setTimestamp(6, new Timestamp(openbareRuimte.getBegindatumTijdvakGeldigheid().getTime()));
                if (openbareRuimte.getEinddatumTijdvakGeldigheid() == null)
                    ps.setNull(7, Types.TIMESTAMP);
                else
                    ps.setTimestamp(7, new Timestamp(openbareRuimte.getEinddatumTijdvakGeldigheid().getTime()));
                ps.setInt(8, openbareRuimte.getInOnderzoek().ordinal());
                ps.setInt(9, openbareRuimte.getOpenbareRuimteType().ordinal());
                ps.setDate(10, new Date(openbareRuimte.getDocumentdatum().getTime()));
                ps.setString(11, openbareRuimte.getDocumentnummer());
                ps.setInt(12, openbareRuimte.getOpenbareruimteStatus().ordinal());
                ps.setLong(13, openbareRuimte.getGerelateerdeWoonplaats());
                ps.setString(14, openbareRuimte.getVerkorteOpenbareRuimteNaam());
                return ps;
            }
        });
    } catch (DataAccessException e) {
        throw new DAOException("Error inserting openbare ruimte: " + openbareRuimte.getIdentificatie(), e);
    }
}

From source file:org.getobjects.eoaccess.EOAdaptorChannel.java

protected void _setStatementParameter(final PreparedStatement _stmt, final int _idx, final int _type,
        final Object _value) throws SQLException {
    if (_stmt == null)
        return;//from w ww  .j ava2s  .com

    /* NULL */

    if (_value == null) {
        _stmt.setNull(_idx, _type);
        return;
    }

    /* values */

    switch (_type) {
    case java.sql.Types.NULL:
        _stmt.setNull(_idx, java.sql.Types.VARCHAR); // CRAP
        break;

    // TODO: customize value processing for types
    case java.sql.Types.VARCHAR:
    case java.sql.Types.TIMESTAMP:
    case java.sql.Types.DATE:
    case java.sql.Types.INTEGER:
    case java.sql.Types.BOOLEAN:
    default:
        if (_value instanceof String)
            _stmt.setString(_idx, (String) _value);
        else if (_value instanceof Boolean)
            _stmt.setBoolean(_idx, (Boolean) _value);
        else if (_value instanceof Integer)
            _stmt.setInt(_idx, (Integer) _value);
        else if (_value instanceof Long)
            _stmt.setLong(_idx, (Long) _value);
        else if (_value instanceof Double)
            _stmt.setDouble(_idx, (Double) _value);
        else if (_value instanceof BigDecimal)
            _stmt.setBigDecimal(_idx, (BigDecimal) _value);
        else if (_value instanceof java.util.Date) {
            _stmt.setTimestamp(_idx, new java.sql.Timestamp(((Date) _value).getTime()));
        } else if (_value instanceof java.sql.Date) {
            /* Note: this is just the DATE component, no TIME */
            _stmt.setDate(_idx, (java.sql.Date) _value);
        } else if (_value instanceof java.util.Calendar) {
            // TBD: shouldn't we use setDate with a proper Calendar?
            final Date vd = ((Calendar) _value).getTime();
            _stmt.setTimestamp(_idx, new java.sql.Timestamp(vd.getTime()));
        } else if (_value instanceof byte[])
            _stmt.setBytes(_idx, (byte[]) _value);
        else {
            log.warn("using String column for value: " + _value + " (" + _value.getClass() + ")");
        }
    }
}

From source file:nl.ordina.bag.etl.dao.AbstractBAGDAO.java

@Override
public void update(final Verblijfsobject verblijfsobject) throws DAOException {
    try {//from  w w  w .  j  a v a2s .c om
        transactionTemplate.execute(new TransactionCallbackWithoutResult() {
            @Override
            protected void doInTransactionWithoutResult(TransactionStatus status) {
                jdbcTemplate.update(new PreparedStatementCreator() {
                    @Override
                    public PreparedStatement createPreparedStatement(Connection connection)
                            throws SQLException {
                        PreparedStatement ps = connection.prepareStatement("update bag_verblijfsobject set"
                                + " aanduiding_record_inactief = ?," + " officieel = ?,"
                                + " verblijfsobject_geometrie = ?," + " oppervlakte_verblijfsobject = ?,"
                                + " verblijfsobject_status = ?," + " einddatum_tijdvak_geldigheid = ?,"
                                + " in_onderzoek = ?," + " bron_documentdatum = ?,"
                                + " bron_documentnummer = ?," + " bag_nummeraanduiding_id = ?"
                                + " where bag_verblijfsobject_id = ?" + " and aanduiding_record_correctie = ?"
                                + " and begindatum_tijdvak_geldigheid = ?");
                        ps.setInt(1, verblijfsobject.getAanduidingRecordInactief().ordinal());
                        ps.setInt(2, verblijfsobject.getOfficieel().ordinal());
                        ps.setString(3, verblijfsobject.getVerblijfsobjectGeometrie());
                        ps.setInt(4, verblijfsobject.getOppervlakteVerblijfsobject());
                        ps.setInt(5, verblijfsobject.getVerblijfsobjectStatus().ordinal());
                        if (verblijfsobject.getEinddatumTijdvakGeldigheid() == null)
                            ps.setNull(6, Types.TIMESTAMP);
                        else
                            ps.setTimestamp(6,
                                    new Timestamp(verblijfsobject.getEinddatumTijdvakGeldigheid().getTime()));
                        ps.setInt(7, verblijfsobject.getInOnderzoek().ordinal());
                        ps.setDate(8, new Date(verblijfsobject.getDocumentdatum().getTime()));
                        ps.setString(9, verblijfsobject.getDocumentnummer());
                        ps.setLong(10, verblijfsobject.getHoofdAdres());
                        ps.setLong(11, verblijfsobject.getIdentificatie());
                        ps.setLong(12, verblijfsobject.getAanduidingRecordCorrectie());
                        ps.setTimestamp(13,
                                new Timestamp(verblijfsobject.getBegindatumTijdvakGeldigheid().getTime()));
                        return ps;
                    }
                });
                deleteGebruikersdoelen(verblijfsobject);
                insertGebruikersdoelen(verblijfsobject);
                deleteNevenadressen(TypeAdresseerbaarObject.VERBLIJFSOBJECT, verblijfsobject);
                insertNevenadressen(TypeAdresseerbaarObject.VERBLIJFSOBJECT, verblijfsobject);
                deleteGerelateerdePanden(verblijfsobject);
                insertGerelateerdePanden(verblijfsobject);
            }
        });
    } catch (DataAccessException e) {
        throw new DAOException("Error updating verblijfsobject: " + verblijfsobject.getIdentificatie(), e);
    }
}

From source file:com.kk.dic.action.Upload.java

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    out = response.getWriter();/*from ww w.  jav  a 2  s . co m*/
    Connection con;
    PreparedStatement pstm = null;
    String fname = "";
    String keyword = "";
    String cd = "";
    String a = (String) request.getSession().getAttribute("email");
    System.out.println("User Name : " + a);
    try {
        boolean isMultipartContent = ServletFileUpload.isMultipartContent(request);
        if (!isMultipartContent) {
            return;
        }
        FileItemFactory factory = new DiskFileItemFactory();
        ServletFileUpload upload = new ServletFileUpload(factory);
        out.print("one");
        try {
            List<FileItem> fields = upload.parseRequest(request);
            Iterator<FileItem> it = fields.iterator();
            if (!it.hasNext()) {
                return;
            }

            while (it.hasNext()) {
                FileItem fileItem = it.next();
                if (fileItem.getFieldName().equals("name")) {
                    fname = fileItem.getString();
                    System.out.println("File Name" + fname);
                } else if (fileItem.getFieldName().equals("keyword")) {
                    keyword = fileItem.getString();
                    System.out.println("File Keyword" + keyword);
                } else {

                }
                boolean isFormField = fileItem.isFormField();
                if (isFormField) {
                } else {
                    out.print("one");
                    try {
                        con = Dbconnection.getConnection();
                        pstm = con.prepareStatement(
                                "insert into files (file, keyword, filetype, filename, CDate, owner, size, data, frank, file_key)values(?,?,?,?,?,?,?,?,?,?)");
                        out.println("getD " + fileItem.getName());
                        String str = getStringFromInputStream(fileItem.getInputStream());
                        // secretkey generating
                        KeyGenerator keyGen = KeyGenerator.getInstance("AES");
                        keyGen.init(128);
                        SecretKey secretKey = keyGen.generateKey();
                        System.out.println("secret key:" + secretKey);
                        //converting secretkey to String
                        byte[] be = secretKey.getEncoded();//encoding secretkey
                        String skey = Base64.encode(be);
                        System.out.println("converted secretkey to string:" + skey);
                        String cipher = new encryption().encrypt(str, secretKey);
                        System.out.println(str);
                        //for get extension from given file
                        String b = fileItem.getName().substring(fileItem.getName().lastIndexOf('.'));
                        System.out.println("File Extension" + b);
                        pstm.setBinaryStream(1, fileItem.getInputStream());
                        pstm.setString(2, keyword);
                        pstm.setString(3, b);
                        pstm.setString(4, fname);
                        pstm.setDate(5, getCurrentDate());
                        pstm.setString(6, a);
                        pstm.setLong(7, fileItem.getSize());
                        pstm.setString(8, cipher);
                        pstm.setString(9, "0");
                        pstm.setString(10, skey);
                        /*Cloud Start*/
                        File f = new File("D:/" + fileItem.getName());
                        out.print("<br/>" + f.getName());
                        FileWriter fw = new FileWriter(f);
                        fw.write(cipher);
                        fw.close();
                        Ftpcon ftpcon = new Ftpcon();
                        ftpcon.upload(f, fname);
                        /*Cloud End*/
                        int i = pstm.executeUpdate();
                        if (i == 1) {
                            response.sendRedirect("upload.jsp?msg=success");
                        } else {
                            response.sendRedirect("upload.jsp?msgg=failed");
                        }
                        con.close();
                    } catch (Exception e) {
                        out.println(e);
                    }
                }
            }
        } catch (Exception ex) {
            out.print(ex);
            Logger.getLogger(Upload.class.getName()).log(Level.SEVERE, null, ex);
        }
    } finally {
        out.close();
    }
}

From source file:org.apache.roller.weblogger.business.startup.DatabaseInstaller.java

/**
 * Upgrade database for Roller 2.0.0/*  ww w. j  a v  a 2 s . c om*/
 */
private void upgradeTo200(Connection con, boolean runScripts) throws StartupException {
    SQLScriptRunner runner = null;
    try {
        if (runScripts) {
            String handle = getDatabaseHandle(con);
            String scriptPath = handle + "/130-to-200-migration.sql";
            successMessage("Running database upgrade script: " + scriptPath);
            runner = new SQLScriptRunner(scripts.getDatabaseScript(scriptPath));
            runner.runScript(con, true);
            messages.addAll(runner.getMessages());
        }

        successMessage("Doing upgrade to 200 ...");
        successMessage("Populating roller_user_permissions table");

        PreparedStatement websitesQuery = con
                .prepareStatement("select w.id as wid, u.id as uid, u.username as uname from "
                        + "website as w, rolleruser as u where u.id=w.userid");
        PreparedStatement websiteUpdate = con.prepareStatement("update website set handle=? where id=?");
        PreparedStatement entryUpdate = con.prepareStatement("update weblogentry set userid=?, status=?, "
                + "pubtime=pubtime, updatetime=updatetime " + "where publishentry=? and websiteid=?");
        PreparedStatement permsInsert = con.prepareStatement("insert into roller_permissions "
                + "(id, username, actions, objectid, objecttype, pending, datecreated) "
                + "values (?,?,?,?,?,?,?)");

        // loop through websites, each has a user
        java.sql.Date now = new java.sql.Date(new Date().getTime());
        ResultSet websiteSet = websitesQuery.executeQuery();
        while (websiteSet.next()) {
            String websiteid = websiteSet.getString("wid");
            String userid = websiteSet.getString("uid");
            String username = websiteSet.getString("uname");
            successMessage("Processing website: " + username);

            // use website user's username as website handle
            websiteUpdate.clearParameters();
            websiteUpdate.setString(1, username);
            websiteUpdate.setString(2, websiteid);
            websiteUpdate.executeUpdate();

            // update all of pubished entries to include userid and status
            entryUpdate.clearParameters();
            entryUpdate.setString(1, userid);
            entryUpdate.setString(2, "PUBLISHED");
            entryUpdate.setBoolean(3, true);
            entryUpdate.setString(4, websiteid);
            entryUpdate.executeUpdate();

            // update all of draft entries to include userid and status
            entryUpdate.clearParameters();
            entryUpdate.setString(1, userid);
            entryUpdate.setString(2, "DRAFT");
            entryUpdate.setBoolean(3, false);
            entryUpdate.setString(4, websiteid);
            entryUpdate.executeUpdate();

            // add  permission for user in website
            permsInsert.clearParameters();
            permsInsert.setString(1, websiteid + "p");
            permsInsert.setString(2, username);
            permsInsert.setString(3, WeblogPermission.ADMIN);
            permsInsert.setString(4, websiteid);
            permsInsert.setString(5, "Weblog");
            permsInsert.setBoolean(6, false);
            permsInsert.setDate(7, now);
            permsInsert.setBoolean(5, false);
            permsInsert.executeUpdate();
        }

        if (!con.getAutoCommit())
            con.commit();

        successMessage("Upgrade to 200 complete.");

    } catch (Exception e) {
        log.error("ERROR running 310 database upgrade script", e);
        if (runner != null)
            messages.addAll(runner.getMessages());

        errorMessage("Problem upgrading database to version 200", e);
        throw new StartupException("Problem upgrading database to version 200", e);
    }

    updateDatabaseVersion(con, 200);
}

From source file:nl.ordina.bag.etl.dao.AbstractBAGDAO.java

@Override
public void insert(final Ligplaats ligplaats) throws DAOException {
    try {/*  w  w  w  . j a v a 2 s.c  o m*/
        transactionTemplate.execute(new TransactionCallbackWithoutResult() {
            @Override
            protected void doInTransactionWithoutResult(TransactionStatus status) {
                jdbcTemplate.update(new PreparedStatementCreator() {
                    @Override
                    public PreparedStatement createPreparedStatement(Connection connection)
                            throws SQLException {
                        PreparedStatement ps = connection
                                .prepareStatement("insert into bag_ligplaats (" + "bag_ligplaats_id,"
                                        + "aanduiding_record_inactief," + "aanduiding_record_correctie,"
                                        + "officieel," + "ligplaats_status," + "ligplaats_geometrie,"
                                        + "begindatum_tijdvak_geldigheid," + "einddatum_tijdvak_geldigheid,"
                                        + "in_onderzoek," + "bron_documentdatum," + "bron_documentnummer,"
                                        + "bag_nummeraanduiding_id" + ") values (?,?,?,?,?,?,?,?,?,?,?,?)");
                        ps.setLong(1, ligplaats.getIdentificatie());
                        ps.setInt(2, ligplaats.getAanduidingRecordInactief().ordinal());
                        ps.setLong(3, ligplaats.getAanduidingRecordCorrectie());
                        ps.setInt(4, ligplaats.getOfficieel().ordinal());
                        ps.setInt(5, ligplaats.getLigplaatsStatus().ordinal());
                        ps.setString(6, ligplaats.getLigplaatsGeometrie());
                        ps.setTimestamp(7, new Timestamp(ligplaats.getBegindatumTijdvakGeldigheid().getTime()));
                        if (ligplaats.getEinddatumTijdvakGeldigheid() == null)
                            ps.setNull(8, Types.TIMESTAMP);
                        else
                            ps.setTimestamp(8,
                                    new Timestamp(ligplaats.getEinddatumTijdvakGeldigheid().getTime()));
                        ps.setInt(9, ligplaats.getInOnderzoek().ordinal());
                        ps.setDate(10, new Date(ligplaats.getDocumentdatum().getTime()));
                        ps.setString(11, ligplaats.getDocumentnummer());
                        ps.setLong(12, ligplaats.getHoofdAdres());
                        return ps;
                    }
                });
                insertNevenadressen(TypeAdresseerbaarObject.LIGPLAATS, ligplaats);
            }
        });
    } catch (DataAccessException e) {
        throw new DAOException("Error inserting ligplaats: " + ligplaats.getIdentificatie(), e);
    }
}

From source file:nl.ordina.bag.etl.dao.AbstractBAGDAO.java

@Override
public void update(final Verblijfsobject origineel, final Verblijfsobject mutation) throws DAOException {
    try {//from   w  w  w .ja  v a 2s. c  o  m
        transactionTemplate.execute(new TransactionCallbackWithoutResult() {
            @Override
            protected void doInTransactionWithoutResult(TransactionStatus status) {
                jdbcTemplate.update(new PreparedStatementCreator() {
                    @Override
                    public PreparedStatement createPreparedStatement(Connection connection)
                            throws SQLException {
                        PreparedStatement ps = connection.prepareStatement("update bag_verblijfsobject set"
                                + " aanduiding_record_inactief = ?," + " aanduiding_record_correctie = ?,"
                                + " officieel = ?," + " verblijfsobject_geometrie = ?,"
                                + " oppervlakte_verblijfsobject = ?," + " verblijfsobject_status = ?,"
                                + " einddatum_tijdvak_geldigheid = ?," + " in_onderzoek = ?,"
                                + " bron_documentdatum = ?," + " bron_documentnummer = ?,"
                                + " bag_nummeraanduiding_id = ?" + " where bag_verblijfsobject_id = ?"
                                + " and aanduiding_record_correctie = ?"
                                + " and begindatum_tijdvak_geldigheid = ?");
                        ps.setInt(1, mutation.getAanduidingRecordInactief().ordinal());
                        ps.setLong(2, mutation.getAanduidingRecordCorrectie());
                        ps.setInt(3, mutation.getOfficieel().ordinal());
                        ps.setString(4, mutation.getVerblijfsobjectGeometrie());
                        ps.setInt(5, mutation.getOppervlakteVerblijfsobject());
                        ps.setInt(6, mutation.getVerblijfsobjectStatus().ordinal());
                        if (mutation.getEinddatumTijdvakGeldigheid() == null)
                            ps.setNull(7, Types.TIMESTAMP);
                        else
                            ps.setTimestamp(7,
                                    new Timestamp(mutation.getEinddatumTijdvakGeldigheid().getTime()));
                        ps.setInt(8, mutation.getInOnderzoek().ordinal());
                        ps.setDate(9, new Date(mutation.getDocumentdatum().getTime()));
                        ps.setString(10, mutation.getDocumentnummer());
                        ps.setLong(11, mutation.getHoofdAdres());
                        ps.setLong(12, origineel.getIdentificatie());
                        ps.setLong(13, origineel.getAanduidingRecordCorrectie());
                        ps.setTimestamp(14,
                                new Timestamp(origineel.getBegindatumTijdvakGeldigheid().getTime()));
                        return ps;
                    }
                });
                deleteGebruikersdoelen(origineel);
                insertGebruikersdoelen(mutation);
                deleteNevenadressen(TypeAdresseerbaarObject.VERBLIJFSOBJECT, origineel);
                insertNevenadressen(TypeAdresseerbaarObject.VERBLIJFSOBJECT, mutation);
                deleteGerelateerdePanden(origineel);
                insertGerelateerdePanden(mutation);
            }
        });
    } catch (DataAccessException e) {
        throw new DAOException("Error updating verblijfsobject: " + origineel.getIdentificatie(), e);
    }
}