List of usage examples for org.springframework.jdbc.core JdbcTemplate update
@Override public int update(String sql, Object[] args, int[] argTypes) throws DataAccessException
From source file:com.kaidad.utilities.MBTilesBase64Converter.java
private static void addTileDataToStringTable(JdbcTemplate c, String tileId, String encodedData) { c.update("insert into images_string (tile_id, tile_data) values (?, ?)", tileId, encodedData); }
From source file:com.company.project.service.dao.UserDao.java
public int insert(String username, String password) { JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); int result = jdbcTemplate.update("insert into users (username, password) values (?, ?)", username, password);//from w w w . j a v a 2 s . c om return result; }
From source file:com.company.project.service.dao.UserDao.java
public int insertx(String username, String password) { DefaultTransactionDefinition def = new DefaultTransactionDefinition(); def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW); TransactionStatus status = txManager.getTransaction(def); int result = 0; try {//from www. j a v a 2s . co m JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); result = jdbcTemplate.update("insert into users (username, password) values (?, ?)", username, password); txManager.commit(status); // will not insert if this line is removed } catch (Exception e) { e.printStackTrace(); txManager.rollback(status); } return result; }
From source file:db.migration.V023__UpdateOrganisationToimipisteKoodi.java
private void updateToimipisteKoodi(Map org, String tpKoodi, JdbcTemplate jdbcTemplate) { String oid = (String) org.get("oid"); int result = jdbcTemplate.update("UPDATE organisaatio SET toimipisteKoodi = ? WHERE oid = ?", tpKoodi, oid); _numUpdated++;// w w w . j a v a2 s . co m if (result < 0 || result > 1) { LOG.error("TP KOODI UPDATED ON {} ORGS for oid = {}", result, oid); } else { LOG.debug(" tp koodi updated for {} to {}", oid, tpKoodi); } }
From source file:org.beast.project.template.config.MyBatisConfig.java
@Override public DataSource dataSource() { EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder(); //DataSource ds = builder.setType(EmbeddedDatabaseType.HSQL).addScript("schema.sql").build(); BasicDataSource basicDataSource = new BasicDataSource(); basicDataSource.setDriverClassName(org.hsqldb.jdbcDriver.class.getName()); basicDataSource.setUsername("sa"); basicDataSource.setPassword(""); basicDataSource.setUrl("jdbc:hsqldb:mem:mydb"); JdbcTemplate jdbcTemplate = new JdbcTemplate(basicDataSource); System.out.println("Creating tables"); jdbcTemplate.execute("drop table person if exists"); jdbcTemplate.execute("create table person(id serial, firstName varchar(50), lastName varchar(50))"); jdbcTemplate.update("INSERT INTO users(firstName, lastName) values (?,?)", "Mike", "Lanyon"); return basicDataSource; }
From source file:db.migration.V055__UpdateECTS.java
private int insertNewMkt(String teksti, JdbcTemplate jdbcTemplate) { int mkt_id = getNextHibernateSequence(jdbcTemplate); if (mkt_id == 0) { LOG.error("Could not get mkt_id."); return 0; } else {/* w w w.j a v a 2 s . co m*/ LOG.debug("mkt_id: {}", mkt_id); // Create new monikielinenteksti int result = jdbcTemplate.update("INSERT INTO monikielinenteksti (id,version) VALUES (?, ?)", mkt_id, 0); if (result < 0 || result > 1) { LOG.error("Failed to INSERT monikielinenteksti: {}.", mkt_id); } else { LOG.info("INSERTED monikielinenteksti: {}.", mkt_id); } // Create new monikielinenteksti_value result = jdbcTemplate.update( "INSERT INTO monikielinenteksti_values (id,value,key,index) VALUES (?, ?, ?, ?)", mkt_id, teksti, "kieli_fi#1", 0); if (result < 0 || result > 1) { LOG.error("Failed to INSERT monikielinenteksti_values: {}.", mkt_id); } else { LOG.info("INSERTED monikielinenteksti_values: {}.", mkt_id); } } return mkt_id; }
From source file:ca.nrc.cadc.cred.server.CertificateDAO.java
public void put(X509CertificateChain chain) { Profiler profiler = new Profiler(this.getClass()); String hashKey = chain.getHashKey(); String canonDn = AuthenticationUtil.canonizeDistinguishedName(chain.getPrincipal().getName()); Date expDate = chain.getExpiryDate(); String certChainStr = chain.certificateString(); byte[] bytesPrivateKey = chain.getPrivateKey().getEncoded(); //TODO just for testing - padded with zeros byte[] testBytesPrivateKey = Arrays.copyOf(bytesPrivateKey, bytesPrivateKey.length + 1); testBytesPrivateKey[testBytesPrivateKey.length - 1] = 1; String csr = chain.getCsrString(); JdbcTemplate jdbc = new JdbcTemplate(config.getDataSource()); if (recordExists(hashKey)) { String sql = "update " + config.getTable() + " set canon_dn = ?, exp_date = ?, cert_chain = ?, private_key = ?, csr = ? where hash_dn=?"; Object[] args = new Object[] { canonDn, expDate, certChainStr, testBytesPrivateKey, csr, hashKey }; int[] argTypes = new int[] { Types.VARCHAR, Types.TIMESTAMP, Types.VARCHAR, Types.VARBINARY, Types.VARCHAR, Types.VARCHAR }; jdbc.update(sql, args, argTypes); } else {/* ww w. jav a2s. co m*/ String sql = "insert into " + config.getTable() + " (canon_dn, exp_date, cert_chain, private_key, csr, hash_dn) values (?,?,?,?,?,?)"; Object[] args = new Object[] { canonDn, expDate, certChainStr, testBytesPrivateKey, csr, hashKey }; int[] argTypes = new int[] { Types.VARCHAR, Types.TIMESTAMP, Types.VARCHAR, Types.VARBINARY, Types.VARCHAR, Types.VARCHAR }; jdbc.update(sql, args, argTypes); } profiler.checkpoint("put"); }
From source file:no.kantega.publishing.common.ao.ContentAOJdbcImpl.java
@Override public ContentIdentifier deleteContent(ContentIdentifier cid) { contentIdHelper.assureContentIdAndAssociationIdSet(cid); int id = cid.getContentId(); // Slett tilgangsrettigheter JdbcTemplate jdbcTemplate = getJdbcTemplate(); jdbcTemplate.update( "delete from objectpermissions where ObjectSecurityId in (select AssociationId from associations where ContentId = ?) and ObjectType = ?", id, ObjectType.ASSOCIATION); // Slett knytninger dette elementet har til andre element og andre elements knytning til dette jdbcTemplate.update("delete from associations where ContentId = ?", id); // Slett innholdsattributter String deleteAttributesSql = "delete from contentattributes where ContentVersionId in (select ContentVersionId from contentversion where ContentId = ?)"; if (dbConnectionFactory.isMySQL()) { deleteAttributesSql = "delete contentattributes from contentattributes,contentversion where contentattributes.contentversionid=contentversion.contentversionid and contentversion.contentid=?"; }/*w w w .j ava2 s . c o m*/ jdbcTemplate.update(deleteAttributesSql, id); try { // Slett hring jdbcTemplate.update( "delete from hearing where ContentVersionId in (select ContentVersionId from contentversion where ContentId = ?)", id); jdbcTemplate .update("delete from hearinginvitee where HearingId not in (select HearingId from hearing)"); jdbcTemplate .update("delete from hearingcomment where HearingId not in (select HearingId from hearing)"); } catch (DataAccessException e1) { // Kunden bruker ikke hring, har ikke tabeller for hring } // Slett vedlegg jdbcTemplate.update("delete from attachments where ContentId = ?", id); jdbcTemplate.update("delete from contentversion where ContentId = ?", id); jdbcTemplate.update("delete from content where ContentId = ?", id); return getParent(cid); }
From source file:no.kantega.publishing.common.ao.ContentAOJdbcImpl.java
private boolean archiveOldVersion(Connection c, Content content, ContentStatus newStatus, boolean newVersionIsActive) throws SQLException { // Find next version JdbcTemplate jdbcTemplate = getJdbcTemplate(); List<Integer> currentVersions = jdbcTemplate.queryForList( "select version from contentversion where ContentId = ? order by version desc", Integer.class, content.getId());/* w w w . j av a 2s. co m*/ if (!currentVersions.isEmpty()) { content.setVersion(currentVersions.get(0) + 1); } if (newStatus == ContentStatus.PUBLISHED) { // Set newStatus = ARCHIVED on currently active version jdbcTemplate.update( "update contentversion set Status = ?, isActive = 0 where ContentId = ? and isActive = 1", ContentStatus.ARCHIVED.getTypeAsInt(), content.getId()); // Publisert blir aktiv versjon newVersionIsActive = true; } return newVersionIsActive; }
From source file:no.kantega.publishing.common.ao.ContentAOJdbcImpl.java
@Override public Content setContentStatus(ContentIdentifier cid, ContentStatus newStatus, Date newPublishDate, String userId) {//w w w . j a v a2 s. c om contentIdHelper.assureContentIdAndAssociationIdSet(cid); int contentId = cid.getContentId(); JdbcTemplate jdbcTemplate = getJdbcTemplate(); List<Integer> versions = jdbcTemplate.queryForList( "select Version from contentversion where ContentId = ? AND status IN (?, ?) order by version desc", Integer.class, contentId, ContentStatus.WAITING_FOR_APPROVAL.getTypeAsInt(), ContentStatus.PUBLISHED_WAITING.getTypeAsInt()); if (versions.isEmpty()) { throw new IllegalStateException("Could not fint content version"); } int version = versions.get(0); if (version != -1) { if (newStatus == ContentStatus.PUBLISHED) { // Sett status = arkivert p aktiv versjon jdbcTemplate.update( "update contentversion set status = ?, isActive = 0 where ContentId = ? and isActive = 1", ContentStatus.ARCHIVED.getTypeAsInt(), contentId); jdbcTemplate.update( "update contentversion set status = ?, isActive = 1, ApprovedBy = ?, ChangeFrom = null where ContentId = ? and Version = ?", ContentStatus.PUBLISHED.getTypeAsInt(), userId, contentId, version); if (newPublishDate != null) { // Set publish date if not set jdbcTemplate.update("update content set PublishDate = ? where ContentId = ?", newPublishDate, contentId); } } else { jdbcTemplate.update("update contentversion set status = ? where ContentId = ? and Version = ?", newStatus.getTypeAsInt(), contentId, cid.getVersion() == -1 ? version : cid.getVersion()); } } Content content = getContent(cid, false); content.setStatus(newStatus); return content; }