概述
import com.mysql.jdbc.Connection; //导入方法依赖的package包/类
@Override
public int execute(MapleClient c, String[] splitted) {
if (splitted.length < 1) {
c.getPlayer().dropMessage(6, "!pnpc ");
return 0;
}
int npcId = Integer.parseInt(splitted[1]);
MapleNPC npc = MapleLifeFactory.getNPC(npcId);
if (npc != null && !npc.getName().equals("MISSINGNO")) {
final int xpos = c.getPlayer().getPosition().x;
final int ypos = c.getPlayer().getPosition().y;
final int fh = c.getPlayer().getMap().getFootholds().findBelow(c.getPlayer().getPosition()).getId();
npc.setPosition(c.getPlayer().getPosition());
npc.setCy(ypos);
npc.setRx0(xpos);
npc.setRx1(xpos);
npc.setFh(fh);
npc.setCustom(true);
try {
Connection con = (Connection) DatabaseConnection.getConnection();
try (PreparedStatement ps = (PreparedStatement) con.prepareStatement("INSERT INTO wz_customlife (dataid, f, hide, fh, cy, rx0, rx1, type, x, y, mid) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")) {
ps.setInt(1, npcId);
ps.setInt(2, 0); // 1 = right , 0 = left
ps.setInt(3, 0); // 1 = hide, 0 = show
ps.setInt(4, fh);
ps.setInt(5, ypos);
ps.setInt(6, xpos);
ps.setInt(7, xpos);
ps.setString(8, "n");
ps.setInt(9, xpos);
ps.setInt(10, ypos);
ps.setInt(11, c.getPlayer().getMapId());
ps.executeUpdate();
}
} catch (SQLException e) {
c.getPlayer().dropMessage(6, "Failed to save NPC to the net.db.");
}
c.getPlayer().getMap().addMapObject(npc);
c.getPlayer().getMap().broadcastMessage(NPCPacket.spawnNPC(npc, true));
c.getPlayer().dropMessage(6, "Please do not reload this map or else the NPC will disappear untill the next restart.");
} else {
c.getPlayer().dropMessage(6, "You have entered an invalid npc id.");
return 0;
}
return 1;
}
最后
以上就是闪闪蓝天为你收集整理的java prepare_Java Connection.prepareStatement方法代码示例的全部内容,希望文章能够帮你解决java prepare_Java Connection.prepareStatement方法代码示例所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复