Java Code Examples for com.mysql.jdbc.exceptions.MySQLDataException

The following examples show how to use com.mysql.jdbc.exceptions.MySQLDataException. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Override
public void loadWorldBan(Player player) {
	Connection con = null;
	try {
		con = DatabaseFactory.getConnection();
		con.setReadOnly(false);
		PreparedStatement stmt = con.prepareStatement("SELECT * FROM player_world_bans WHERE `player` = ?");
		stmt.setInt(1, player.getObjectId());
		ResultSet rs = stmt.executeQuery();
		if (rs.next()) {
			player.setBannedFromWorld(rs.getString("by"), rs.getString("reason"), rs.getLong("duration"), new Date(rs.getLong("date")));
		}
		rs.close();
		stmt.close();
	}
	catch (MySQLDataException mde) {
	}
	catch (Exception e) {
		log.error("cannot load world ban for player #" + player.getObjectId());
		log.warn(e.getMessage());
	}
	finally {
		DatabaseFactory.close(con);
	}
}
 
Example 2
@Override
public void removeWorldBan(int playerObjId) {
	String query = "DELETE FROM player_world_bans WHERE `player` = ?";
	Connection con = null;
	try {
		con = DatabaseFactory.getConnection();
		con.setReadOnly(false);
		PreparedStatement stmt = con.prepareStatement(query);
		stmt.setInt(1, playerObjId);
		stmt.execute();
		stmt.close();
	}
	catch (MySQLDataException mde) {
	}
	catch (Exception e) {
		log.error("cannot delete world ban for player #" + playerObjId);
		log.warn(e.getMessage());
	}
	finally {
		DatabaseFactory.close(con);
	}
}
 
Example 3
@Override
public boolean addWorldBan(int playerObjId, String by, long duration, Date date, String reason) {
	String query = "SELECT * FROM player_world_bans WHERE `player` = ?";
	Connection con = null;
	boolean result = false;
	try {
		con = DatabaseFactory.getConnection();
		con.setReadOnly(false);
		PreparedStatement stmt = con.prepareStatement(query);
		stmt.setInt(1, playerObjId);
		ResultSet rset = stmt.executeQuery();
		if (!rset.next()) {
			query = "INSERT INTO player_world_bans(`player`, `by`, `duration`, `date`, `reason`) VALUES (?,?,?,?,?)";
			stmt = con.prepareStatement(query);
			stmt.setInt(1, playerObjId);
			stmt.setString(2, by);
			stmt.setLong(3, duration);
			stmt.setLong(4, date.getTime());
			stmt.setString(5, reason);
			stmt.execute();
			stmt.close();
			result = true;
		}
		else {
			log.warn("player #" + playerObjId + " already banned");
			result = false;
		}
	}
	catch (MySQLDataException mde) {
		result = false;
	}
	catch (Exception e) {
		log.error("cannot insert world ban for player #" + playerObjId);
		log.warn(e.getMessage());
		result = false;
	}
	finally {
		DatabaseFactory.close(con);
	}
	return result;
}