当前位置: 首页>>代码示例>>Java>>正文


Java MySQLIntegrityConstraintViolationException类代码示例

本文整理汇总了Java中com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException的典型用法代码示例。如果您正苦于以下问题:Java MySQLIntegrityConstraintViolationException类的具体用法?Java MySQLIntegrityConstraintViolationException怎么用?Java MySQLIntegrityConstraintViolationException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


MySQLIntegrityConstraintViolationException类属于com.mysql.jdbc.exceptions.jdbc4包,在下文中一共展示了MySQLIntegrityConstraintViolationException类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: delete

import com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException; //导入依赖的package包/类
public void delete(int row) throws Exception {
    ExecuteUpdateCommand command = new ExecuteUpdateCommand();
    command.setSqlString(getDelete(row));
    command = (ExecuteUpdateCommand)BisisApp.getJdbcService().executeCommand(command);
    
    if (command != null){
     if (command.getRowCount() == 1){
   	  data.remove(row);
      fireTableDataChanged(); 
     } else if (command.getException() instanceof MySQLIntegrityConstraintViolationException){
   	  throw new HoldingsIntegrityViolationException
			("\u0160ifra ne mo\u017ee biti obrisana!\nPostoje primerci/godine/sveske za koje je uneta selektovana \u0161ifra.");
     } else {
	 throw command.getException();
     }
    } else {
  	  throw new Exception ("Gre\u0161ka u konekciji s bazom podataka!");
    }
}
 
开发者ID:unsftn,项目名称:bisis-v4,代码行数:20,代码来源:CoderTableModel.java

示例2: persist

import com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException; //导入依赖的package包/类
@Override
public int persist(SearchQueryVO obj) throws SQLException {
	int r =0;
	Connection con=DBConnection.getSingleConnection();
	try{
	 //con = DBConnection.getConnection();
	String query  = "insert into "+tableName+" (query,jsonpath,result,timestamp)values(?,?,?,?)";
	PreparedStatement preparedStatement = con.prepareStatement(query);
	//preparedStatement.setLong(1, obj.getSongId());
	preparedStatement.setString(1, obj.getQuery());
	preparedStatement.setString(2, obj.getJsonPath());
	preparedStatement.setString(3, obj.getResult());
	preparedStatement.setTimestamp(4, new Timestamp(System.currentTimeMillis()));
	r=preparedStatement.executeUpdate(); 
	
	}
	catch(MySQLIntegrityConstraintViolationException ex){
		System.out.println( "QUERY IS ALREADY THERE: "+obj.getQuery());
	}
	finally{
		con.close();
		
	}
	
	return r;	
}
 
开发者ID:vjymits,项目名称:musicFinder,代码行数:27,代码来源:SearchQueryDao.java

示例3: persistAndRetryIfMacCollision

import com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException; //导入依赖的package包/类
private VmNicVO persistAndRetryIfMacCollision(VmNicVO vo) {
    int tries = 5;
    while (tries-- > 0) {
        try {
            vo = dbf.persistAndRefresh(vo);
            return vo;
        } catch (JpaSystemException e) {
            if (e.getRootCause() instanceof MySQLIntegrityConstraintViolationException &&
                    e.getRootCause().getMessage().contains("Duplicate entry")) {
                logger.debug(String.format("Concurrent mac allocation. Mac[%s] has been allocated, try allocating another one. " +
                        "The error[Duplicate entry] printed by jdbc.spi.SqlExceptionHelper is no harm, " +
                        "we will try finding another mac", vo.getMac()));
                logger.trace("", e);
                vo.setMac(NetworkUtils.generateMacWithDeviceId((short) vo.getDeviceId()));
            } else {
                throw e;
            }
        }
    }
    return null;
}
 
开发者ID:zstackio,项目名称:zstack,代码行数:22,代码来源:VmAllocateNicFlow.java

示例4: executeQuery

import com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException; //导入依赖的package包/类
public ResultSet executeQuery( PreparedStatement pstmt, Void result ) throws SQLException, SiteException {
	try {
		pstmt.executeUpdate();
	}catch( MySQLIntegrityConstraintViolationException e ){
		//This exception is thrown in case there is already one avatar image for 
		//the user. Note that, it should be caught before being passed to the client!!!
		throw new InternalSiteException("The user Avatar image already exists!");
	}
	return null;
}
 
开发者ID:ivan-zapreev,项目名称:x-cure-chat,代码行数:11,代码来源:InsertNewProfileAvatarExecutor.java

示例5: persist

import com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException; //导入依赖的package包/类
@Override
public int persist(AsyncSearchVO obj) throws SQLException {
	int r =0;
	Connection con=DBConnection.getSingleConnection();
	try{
	 //con = DBConnection.getConnection();
	String query  = "insert into "+table+" (uuid,query,result_uri,search_type,tables,timeinMS,timestamp)values(?,?,?,?,?,?,?)";
	PreparedStatement preparedStatement = con.prepareStatement(query);
	
	preparedStatement.setString(1, obj.getUuid());
	preparedStatement.setString(2, obj.getQuery());
	preparedStatement.setString(3, obj.getResultUri());
	preparedStatement.setString(4, obj.getSearchType());
	preparedStatement.setString(5, obj.getTables());
	preparedStatement.setLong(6, obj.getTimeinMS());
	preparedStatement.setTimestamp(7, new Timestamp(System.currentTimeMillis()));
	r=preparedStatement.executeUpdate(); 
	
	}
	catch(MySQLIntegrityConstraintViolationException ex){
		System.out.println( "QUERY IS ALREADY THERE: "+obj.getQuery());
	}
	finally{
		con.close();
		
	}
	
	return r;	
	
}
 
开发者ID:vjymits,项目名称:musicFinder,代码行数:31,代码来源:AsyncSearchDao.java

示例6: persist

import com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException; //导入依赖的package包/类
public int persist(ConfigVO obj) throws SQLException {
	int r =0;
	Connection con=DBConnection.getSingleConnection();
	try{
	 //con = DBConnection.getConnection();
	String query  = "insert into music.config (category,instance,component,name,value,description)values(?,?,?,?,?,?)";
	PreparedStatement preparedStatement = con.prepareStatement(query);
	
	preparedStatement.setString(1, obj.getCategory());
	preparedStatement.setString(2, obj.getInstance());
	preparedStatement.setString(3, obj.getComponent());
	preparedStatement.setString(4, obj.getName());
	preparedStatement.setString(5, obj.getValue());
	preparedStatement.setString(6, obj.getDescription());
	
	r=preparedStatement.executeUpdate(); 
	
	}
	catch(MySQLIntegrityConstraintViolationException ex){
		System.out.println( "Config IS ALREADY THERE: "+obj.getName());
	}
	finally{
		con.close();
		
	}
	
	return r;	
}
 
开发者ID:vjymits,项目名称:musicFinder,代码行数:29,代码来源:ConfigDao.java

示例7: create

import com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException; //导入依赖的package包/类
@Override
public boolean create(Document_Organisation obj) throws SQLException {
    boolean result = false;
    if (obj.getDoc() == null || obj.getOrgs() == null) {
        throw new IllegalArgumentException("No Document nor organisation is already created, the Affiliation ID is not null.");
    }

    PreparedStatement statement = null;

    try {
        statement = connect.prepareStatement(SQL_INSERT, Statement.RETURN_GENERATED_KEYS);


        for (Organisation org : obj.getOrgs()) {
            try {
                statement.setString(1, obj.getDoc().getDocID());
                statement.setLong(2, org.getOrganisationId());
                statement.executeUpdate();

                result = true;
            } catch (MySQLIntegrityConstraintViolationException e) {
            }
        }
    } finally {
        closeQuietly(statement);
    }

    return result;
}
 
开发者ID:anHALytics,项目名称:anhalytics-core,代码行数:30,代码来源:Document_OrganisationDAO.java

示例8: handle

import com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException; //导入依赖的package包/类
private void handle(APICreateLdapBindingMsg msg) {
    APICreateLdapBindingEvent evt = new APICreateLdapBindingEvent(msg.getId());

    // account check
    SimpleQuery<AccountVO> sq = dbf.createQuery(AccountVO.class);
    sq.add(AccountVO_.uuid, SimpleQuery.Op.EQ, msg.getAccountUuid());
    AccountVO avo = sq.find();
    if (avo == null) {
        evt.setError(errf.instantiateErrorCode(LdapErrors.CANNOT_FIND_ACCOUNT,
                String.format("cannot find the specified account[uuid:%s]", msg.getAccountUuid())));
        bus.publish(evt);
        return;
    }

    String ldapUseAsLoginName = LdapUtil.getLdapUseAsLoginName();

    // bind op
    LdapTemplateContextSource ldapTemplateContextSource = readLdapServerConfiguration();
    String fullDn = msg.getLdapUid();
    if (!validateDnExist(ldapTemplateContextSource, fullDn)) {
        throw new OperationFailureException(errf.instantiateErrorCode(LdapErrors.UNABLE_TO_GET_SPECIFIED_LDAP_UID,
                String.format("cannot find dn[%s] on ldap server[Address:%s, BaseDN:%s].", fullDn,
                        String.join(", ", ldapTemplateContextSource.getLdapContextSource().getUrls()),
                        ldapTemplateContextSource.getLdapContextSource().getBaseLdapPathAsString())));
    }
    try {
        evt.setInventory(bindLdapAccount(msg.getAccountUuid(), fullDn));
        logger.info(String.format("create ldap binding[ldapUid=%s, ldapUseAsLoginName=%s] success", fullDn, ldapUseAsLoginName));
    } catch (JpaSystemException e) {
        if (e.getRootCause() instanceof MySQLIntegrityConstraintViolationException) {
            evt.setError(errf.instantiateErrorCode(LdapErrors.BIND_SAME_LDAP_UID_TO_MULTI_ACCOUNT,
                    "The ldap uid has been bound to an account. "));
        } else {
            throw e;
        }
    }
    bus.publish(evt);
}
 
开发者ID:zstackio,项目名称:zstack,代码行数:39,代码来源:LdapManagerImpl.java

示例9: reserveIp

import com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException; //导入依赖的package包/类
@Override
public UsedIpInventory reserveIp(IpRangeInventory ipRange, String ip) {
    try {
        UsedIpVO vo = new UsedIpVO(ipRange.getUuid(), ip);
        vo.setIpInLong(NetworkUtils.ipv4StringToLong(ip));
        String uuid = ipRange.getUuid() + ip;
        uuid = UUID.nameUUIDFromBytes(uuid.getBytes()).toString().replaceAll("-", "");
        vo.setUuid(uuid);
        vo.setL3NetworkUuid(ipRange.getL3NetworkUuid());
        vo.setNetmask(ipRange.getNetmask());
        vo.setGateway(ipRange.getGateway());
        vo = dbf.persistAndRefresh(vo);
        return UsedIpInventory.valueOf(vo);
    } catch (JpaSystemException e) {
        if (e.getRootCause() instanceof MySQLIntegrityConstraintViolationException) {
            logger.debug(String.format("Concurrent ip allocation. " +
                    "Ip[%s] in ip range[uuid:%s] has been allocated, try allocating another one. " +
                    "The error[Duplicate entry] printed by jdbc.spi.SqlExceptionHelper is no harm, " +
                    "we will try finding another ip", ip, ipRange.getUuid()));
            logger.trace("", e);
        } else {
            throw e;
        }
    }

    return null;
}
 
开发者ID:zstackio,项目名称:zstack,代码行数:28,代码来源:L3NetworkManagerImpl.java

示例10: updateEO

import com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException; //导入依赖的package包/类
private void updateEO(Object entity, DataIntegrityViolationException de) {
    if (!MySQLIntegrityConstraintViolationException.class.isAssignableFrom(de.getRootCause().getClass())) {
        throw de;
    }

    MySQLIntegrityConstraintViolationException me = (MySQLIntegrityConstraintViolationException) de.getRootCause();
    if (!(me.getErrorCode() == 1062 && "23000".equals(me.getSQLState()) && me.getMessage().contains("PRIMARY"))) {
        throw de;
    }

    if (!hasEO()) {
        throw de;
    }

    // at this point, the error is caused by a update tried on VO entity which has been soft deleted. This is mostly
    // caused by a deletion cascade(e.g deleting host will cause vm running on it to be deleted, and deleting vm is trying to return capacity
    // to host which has been soft deleted, because vm deletion is executed in async manner). In this case, we make the update to EO table

    Object idval = getEOPrimaryKeyValue(entity);
    Object eo = getEntityManager().find(eoClass, idval);
    final Object deo = ObjectUtils.copy(eo, entity);
    new Runnable() {
        @Override
        @Transactional(propagation = Propagation.REQUIRES_NEW)
        public void run() {
            getEntityManager().merge(deo);
        }
    }.run();
    logger.debug(String.format("A EO[%s] update has been made", eoClass.getName()));
}
 
开发者ID:zstackio,项目名称:zstack,代码行数:31,代码来源:DatabaseFacadeImpl.java

示例11: removeUserFromRole

import com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException; //导入依赖的package包/类
/**
 * does what it says
 * 
 * @param user
 * @throws DBOperationException
 */
public void removeUserFromRole(User user) throws DBOperationException {
	if (user.getId() == -1 || this.getId() == -1) {
		throw new DBOperationException(
				"User or Role is not correctly configured and has no id");
	}
	if (users == null)
		users = new ArrayList();
	else if (!users.contains(user))
		return;

	// return the favor
	user.getRoles().remove(this);

	UserRoleIdxExample userRole = new UserRoleIdxExample();
	Criteria crit = userRole.createCriteria();
	crit.andRoleIdEqualTo(this.id);
	crit.andUserIdEqualTo(user.getId());

	SqlSession session = null;
	try {
		session = MyBatisConnectionFactory.getSqlSessionFactory()
				.openSession(true);

		// get it
		UserRoleIdx ur = session.selectOne(
				"io.starter.dao.UserRoleIdxMapper.selectByExample", userRole);

		session.delete("io.starter.dao.UserRoleIdxMapper.deleteByPrimaryKey",
				ur.getId());

	} catch (Exception e) {
		if (session != null)
			session.close();
		if (!(e.getCause() instanceof MySQLIntegrityConstraintViolationException)) {
			throw new DBOperationException(e.toString());
		}
		// otherwise record already exists, just move on
	} finally {
		if (session != null)
			session.close();
	}
	if (users != null)
		users.remove(user);
	if (session != null)
		session.close();

}
 
开发者ID:StarterInc,项目名称:Ignite,代码行数:54,代码来源:Role.java


注:本文中的com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。