com.l2jfree.gameserver.datatables.PetNameTable.java Source code

Java tutorial

Introduction

Here is the source code for com.l2jfree.gameserver.datatables.PetNameTable.java

Source

/*
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU General Public License along with
 * this program. If not, see <http://www.gnu.org/licenses/>.
 */
package com.l2jfree.gameserver.datatables;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.l2jfree.L2DatabaseFactory;

public class PetNameTable {
    private final static Log _log = LogFactory.getLog(PetNameTable.class);

    public static boolean doesPetNameExist(String name, int petNpcId) {
        boolean result = true;
        Connection con = null;

        try {
            con = L2DatabaseFactory.getInstance().getConnection(con);
            PreparedStatement statement = con.prepareStatement(
                    "SELECT name FROM pets p, items i WHERE p.item_obj_id = i.object_id AND name=? AND i.item_id=?");
            statement.setString(1, name);
            statement.setString(2, Integer.toString(PetDataTable.getItemIdByPetId(petNpcId)));
            ResultSet rset = statement.executeQuery();
            result = rset.next();
            rset.close();
            statement.close();
        } catch (SQLException e) {
            _log.warn("could not check existing petname:" + e.getMessage(), e);
        } finally {
            L2DatabaseFactory.close(con);
        }

        return result;
    }
}