當前位置: 首頁>>代碼示例>>Java>>正文


Java Connection.prepareStatement方法代碼示例

本文整理匯總了Java中com.mysql.jdbc.Connection.prepareStatement方法的典型用法代碼示例。如果您正苦於以下問題:Java Connection.prepareStatement方法的具體用法?Java Connection.prepareStatement怎麽用?Java Connection.prepareStatement使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.mysql.jdbc.Connection的用法示例。


在下文中一共展示了Connection.prepareStatement方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: insert

import com.mysql.jdbc.Connection; //導入方法依賴的package包/類
public int insert(Map<String,String> sql,Connection conn,PrintWriter stdout) {
 String sql_exec = "INSERT INTO httplog(url,method,header,body) VALUE(?,?,?,?)";
 try {
	PreparedStatement ps = conn.prepareStatement(sql_exec);
	ps.setString(1, sql.get("url"));
	ps.setString(2, sql.get("method"));
	ps.setString(3, sql.get("headers"));
	ps.setString(4, sql.get("body"));
	int i = ps.executeUpdate();
	stdout.println("[+] insert ["+i+"] row ");
	return i;
} catch (SQLException e) {
	e.printStackTrace();
}
 
 return 0;
}
 
開發者ID:ibey0nd,項目名稱:NSTProxy,代碼行數:18,代碼來源:jdbcUtils.java

示例2: queryrepeat

import com.mysql.jdbc.Connection; //導入方法依賴的package包/類
public int queryrepeat(String url,String body,Connection conn) {
 String sql_exec = "SELECT COUNT(*) as count FROM httplog WHERE url=? AND body = ?";
 int flag = 0;
 try {
	PreparedStatement ps = conn.prepareStatement(sql_exec);
	ps.setString(1, url);
	ps.setString(2, body);
	ResultSet rs = ps.executeQuery();
	while (rs.next()) {
		flag = rs.getInt("count");
	}
	return flag;
	
} catch (SQLException e) {
	e.printStackTrace();
}
 
return 0;
}
 
開發者ID:ibey0nd,項目名稱:NSTProxy,代碼行數:20,代碼來源:jdbcUtils.java

示例3: execute

import com.mysql.jdbc.Connection; //導入方法依賴的package包/類
@Override
public int execute(MapleClient c, String[] splitted) {
    try {
        Connection con = (Connection) DatabaseConnection.getConnection();
        PreparedStatement ps = (PreparedStatement) con.prepareStatement(StringUtil.joinStringFrom(splitted, 1));
        ps.executeUpdate();
    } catch (SQLException e) {
        c.getPlayer().dropMessage(0, "Failed to execute SQL command.");
        return 0;
    }
    return 1;
}
 
開發者ID:ergothvs,項目名稱:Lucid2.0,代碼行數:13,代碼來源:AdminCommand.java

示例4: loadCustomLife

import com.mysql.jdbc.Connection; //導入方法依賴的package包/類
public static int loadCustomLife() {
    customLife.clear(); // init
    try {
        Connection con = (Connection) DatabaseConnection.getConnection();
        try (java.sql.PreparedStatement ps = con.prepareStatement("SELECT * FROM `wz_customlife`"); ResultSet rs = ps.executeQuery()) {
            while (rs.next()) {
                final int mapid = rs.getInt("mid");
                final AbstractLoadedMapleLife myLife = loadLife(rs.getInt("dataid"), rs.getInt("f"), rs.getByte("hide") > 0, rs.getInt("fh"), rs.getInt("cy"), rs.getInt("rx0"), rs.getInt("rx1"), rs.getInt("x"), rs.getInt("y"), rs.getString("type"), rs.getInt("mobtime"));
                if (myLife == null) {
                    continue;
                }
                final List<AbstractLoadedMapleLife> entries = customLife.get(mapid);
                final List<AbstractLoadedMapleLife> collections = new ArrayList<>();
                if (entries == null) {
                    collections.add(myLife);
                    customLife.put(mapid, collections);
                } else {
                    collections.addAll(entries); //re-add
                    collections.add(myLife);
                    customLife.put(mapid, collections);
                }
            }
        }
        loadCustomNPC();
        return customLife.size();
        //System.out.println("Successfully loaded " + customLife.size() + " maps with custom life.");
    } catch (SQLException e) {
        System.out.println("Error loading custom life..." + e);
    }
    return -1;
}
 
開發者ID:ergothvs,項目名稱:Lucid2.0,代碼行數:32,代碼來源:MapleMapFactory.java

示例5: execute

import com.mysql.jdbc.Connection; //導入方法依賴的package包/類
@Override
public int execute(MapleClient c, String[] splitted) {
    if (splitted.length < 1) {
        c.getPlayer().dropMessage(6, "!pnpc <npcid>");
        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;
}
 
開發者ID:ergothvs,項目名稱:Lucid2.0,代碼行數:47,代碼來源:SuperGMCommand.java


注:本文中的com.mysql.jdbc.Connection.prepareStatement方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。