本文整理汇总了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) {
}
}
}
}
}