本文整理匯總了Java中com.dsh105.echopet.compat.api.util.SQLUtil類的典型用法代碼示例。如果您正苦於以下問題:Java SQLUtil類的具體用法?Java SQLUtil怎麽用?Java SQLUtil使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
SQLUtil類屬於com.dsh105.echopet.compat.api.util包,在下文中一共展示了SQLUtil類的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: clearRiderFromDatabase
import com.dsh105.echopet.compat.api.util.SQLUtil; //導入依賴的package包/類
@Override
public void clearRiderFromDatabase(String playerIdent) {
if (EchoPet.getOptions().useSql()) {
Connection con = null;
PreparedStatement ps = null;
if (EchoPet.getPlugin().getDbPool() != null) {
try {
con = EchoPet.getPlugin().getDbPool().getConnection();
ps = con.prepareStatement("UPDATE " + TableMigrationUtil.LATEST_TABLE + " SET RiderData = ? WHERE OwnerName = ?;");
ps.setLong(1, SQLUtil.serializePetData(Arrays.asList(PetData.values())));
ps.setString(2, String.valueOf(playerIdent));
ps.executeUpdate();
} catch (SQLException e) {
Logger.log(Logger.LogLevel.SEVERE, "Failed to retrieve Pet data for " + playerIdent + " in MySQL Database", e, true);
} finally {
try {
if (ps != null) {
ps.close();
}
if (con != null) {
con.close();
}
} catch (SQLException ignored) {
}
}
}
}
}
示例2: saveToDatabase
import com.dsh105.echopet.compat.api.util.SQLUtil; //導入依賴的package包/類
@Override
public void saveToDatabase(String playerIdent, PetType petType, String petName, List<PetData> petData, boolean isRider) {
if (EchoPet.getOptions().useSql()) {
Connection con = null;
PreparedStatement ps = null;
if (EchoPet.getPlugin().getDbPool() != null) {
try {
con = EchoPet.getPlugin().getDbPool().getConnection();
// Delete any existing info
if (!isRider) {
this.clearFromDatabase(playerIdent);
}
// Deal with the pet metadata first
// This tends to be more problematic, so by shoving it out of the way, we can get the pet data saved.
if (isRider) {
ps = con.prepareStatement("UPDATE " + TableMigrationUtil.LATEST_TABLE + " SET RiderPetType = ?, RiderPetName = ?, RiderPetData = ? WHERE OwnerName = ?");
ps.setString(1, petType.toString());
ps.setString(2, petName);
ps.setLong(3, SQLUtil.serializePetData(petData));
ps.setString(4, String.valueOf(playerIdent));
ps.executeUpdate();
} else {
ps = con.prepareStatement("INSERT INTO " + TableMigrationUtil.LATEST_TABLE + " (OwnerName, PetType, PetName, PetData) VALUES (?, ?, ?, ?)");
ps.setString(1, String.valueOf(playerIdent));
ps.setString(2, petType.toString());
ps.setString(3, petName);
ps.setLong(4, SQLUtil.serializePetData(petData));
ps.executeUpdate();
}
} catch (SQLException e) {
Logger.log(Logger.LogLevel.SEVERE, "Failed to save Pet data for " + playerIdent + " to MySQL Database", e, true);
} finally {
try {
if (ps != null) {
ps.close();
}
if (con != null) {
con.close();
}
} catch (SQLException ignored) {
}
}
}
}
}