当前位置: 首页>>代码示例>>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;未经允许,请勿转载。