当前位置: 首页>>代码示例>>Java>>正文


Java PreparedStatement.getUpdateCount方法代码示例

本文整理汇总了Java中java.sql.PreparedStatement.getUpdateCount方法的典型用法代码示例。如果您正苦于以下问题:Java PreparedStatement.getUpdateCount方法的具体用法?Java PreparedStatement.getUpdateCount怎么用?Java PreparedStatement.getUpdateCount使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.sql.PreparedStatement的用法示例。


在下文中一共展示了PreparedStatement.getUpdateCount方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: populateTables

import java.sql.PreparedStatement; //导入方法依赖的package包/类
@Before
public void populateTables()
{
    // Populate tables.
    for (Data d : data) {
        String q = String.format("insert into %s values(?, ?)", d.tablename);
        for (String id : d.good) {
            try {
                PreparedStatement sel = conn.prepareStatement(q);
                sel.setString(1, id);
                sel.setString(2, String.format("VALUE:%s:%s", d.tablename, id));
                sel.execute();
                int count = sel.getUpdateCount();
                assertTrue(count==1);
            }
            catch(SQLException e) {
                System.err.printf("ERROR(INSERT): %s value='%s': %s\n",
                        d.typename, d.good[0], e.getMessage());
                fail();
            }
        }
    }
    populateContestants();
    populateVotes();
    
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:27,代码来源:TestJDBCQueries.java

示例2: populateContestants

import java.sql.PreparedStatement; //导入方法依赖的package包/类
private void populateContestants() {
    String q = "insert into contestants values(?, ?)";
    for (int i = 0; i < TABLE_SIZE; i++) {
        try {
            PreparedStatement sel = conn.prepareStatement(q);
            
            sel.setInt(1, i);
            sel.setString(2, "constants" + i);
            sel.execute();
            int count = sel.getUpdateCount();
            assertTrue(count==1);
        }
        catch(SQLException e) {
            System.err.printf("ERROR(INSERT): %s value='%s': %s\n",
                    "votes", i, e.getMessage());
            fail();
        }
    }
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:20,代码来源:TestJDBCQueries.java

示例3: execute

import java.sql.PreparedStatement; //导入方法依赖的package包/类
@Override
public ResultSet execute(PreparedStatement statement) {
	// sql logged by StatementPreparerImpl
	try {
		final ResultSet rs;
		try {
			jdbcCoordinator.getTransactionCoordinator().getTransactionContext().startStatementExecution();
			if ( !statement.execute() ) {
				while ( !statement.getMoreResults() && statement.getUpdateCount() != -1 ) {
					// do nothing until we hit the resultset
				}
			}
			rs = statement.getResultSet();
		}
		finally {
			jdbcCoordinator.getTransactionCoordinator().getTransactionContext().endStatementExecution();
		}
		postExtract( rs, statement );
		return rs;
	}
	catch (SQLException e) {
		throw sqlExceptionHelper.convert( e, "could not execute statement" );
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:25,代码来源:ResultSetReturnImpl.java

示例4: jailOfflinePlayer

import java.sql.PreparedStatement; //导入方法依赖的package包/类
public static void jailOfflinePlayer(String name, int delay)
{
	try (Connection con = L2DatabaseFactory.getInstance().getConnection())
	{
		PreparedStatement statement = con.prepareStatement("UPDATE characters SET x=?, y=?, z=?, punish_level=?, punish_timer=? WHERE char_name=?");
		statement.setInt(1, -114356);
		statement.setInt(2, -249645);
		statement.setInt(3, -2984);
		statement.setInt(4, L2PcInstance.PunishLevel.JAIL.value());
		statement.setLong(5, (delay > 0 ? delay * 60000L : 0));
		statement.setString(6, name);
		
		statement.execute();
		int count = statement.getUpdateCount();
		statement.close();
		
	}
	catch (SQLException se)
	{
	}
}
 
开发者ID:Elfocrash,项目名称:L2ACP-api,代码行数:22,代码来源:Helpers.java

示例5: unjailOfflinePlayer

import java.sql.PreparedStatement; //导入方法依赖的package包/类
public static void unjailOfflinePlayer(String name)
{
	try (Connection con = L2DatabaseFactory.getInstance().getConnection())
	{
		PreparedStatement statement = con.prepareStatement("UPDATE characters SET x=?, y=?, z=?, punish_level=?, punish_timer=? WHERE char_name=?");
		statement.setInt(1, 17836);
		statement.setInt(2, 170178);
		statement.setInt(3, -3507);
		statement.setInt(4, 0);
		statement.setLong(5, 0);
		statement.setString(6, name);
		statement.execute();
		int count = statement.getUpdateCount();
		statement.close();
	}
	catch (SQLException se)
	{
	}
}
 
开发者ID:Elfocrash,项目名称:L2ACP-api,代码行数:20,代码来源:Helpers.java

示例6: doBatch

import java.sql.PreparedStatement; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 *
 * @see jp.co.future.uroborosql.filter.AbstractSqlFilter#doBatch(jp.co.future.uroborosql.context.SqlContext, java.sql.PreparedStatement, int[])
 */
@Override
public int[] doBatch(final SqlContext sqlContext, final PreparedStatement preparedStatement, final int[] result) {
	if (LOG.isDebugEnabled()) {
		int[] counts = result;
		try {
			counts = new int[] { preparedStatement.getUpdateCount() };
		} catch (SQLException ex) {
			ex.printStackTrace();
		}

		StringBuilder builder = new StringBuilder();
		for (int val : counts) {
			builder.append(val).append(", ");
		}
		LOG.debug("SQL:{} executed. Result:{}", sqlContext.getSqlName(), builder.toString());
	}
	return result;
}
 
开发者ID:future-architect,项目名称:uroborosql,代码行数:24,代码来源:DebugSqlFilter.java

示例7: testInsertDrop

import java.sql.PreparedStatement; //导入方法依赖的package包/类
@Test public void testInsertDrop() throws Exception {
  final String t = AvaticaUtils.unique("TEST_TABLE2");
  final String create =
      String.format(Locale.ROOT, "create table if not exists %s ("
          + "id int not null, "
          + "msg varchar(3) not null)", t);
  final String insert = String.format(Locale.ROOT,
      "insert into %s values(1, 'foo')", t);
  Connection connection = ljs();
  Statement statement = connection.createStatement();
  statement.execute(create);

  Statement stmt = connection.createStatement();
  int count = stmt.executeUpdate(insert);
  assertThat(count, is(1));
  ResultSet resultSet = stmt.getResultSet();
  assertThat(resultSet, nullValue());

  PreparedStatement pstmt = connection.prepareStatement(insert);
  boolean status = pstmt.execute();
  assertThat(status, is(false));
  int updateCount = pstmt.getUpdateCount();
  assertThat(updateCount, is(1));
}
 
开发者ID:apache,项目名称:calcite-avatica,代码行数:25,代码来源:RemoteDriverTest.java

示例8: jailOfflinePlayer

import java.sql.PreparedStatement; //导入方法依赖的package包/类
private void jailOfflinePlayer(String name, int delay)
{
	Connection con = null;
  	try
   	{
   		con = L2DatabaseFactory.getInstance().getConnection();

   		PreparedStatement statement = con.prepareStatement("UPDATE characters SET x=?, y=?, z=?, punish_level=?, punish_timer=? WHERE char_name=?");
   		statement.setInt(1, -114356);
   		statement.setInt(2, -249645);
   		statement.setInt(3, -2984);
   		statement.setInt(4, L2PcInstance.PunishLevel.JAIL.value());
   		statement.setLong(5, delay * 60000L);
   		statement.setString(6, name);

		statement.execute();
		int count = statement.getUpdateCount();
		statement.close();

		if (count == 0)
			_print.println("Character not found!");
		else
			_print.println("Character "+name+" jailed for "+(delay>0 ? delay+" minutes." : "ever!"));
   	} catch (SQLException se)
   	{
   		_print.println("SQLException while jailing player");
        if (Config.DEBUG) se.printStackTrace();
   	} finally
   	{
   		try { con.close(); } catch (Exception e) {}
   	}
}
 
开发者ID:L2jBrasil,项目名称:L2jBrasil,代码行数:33,代码来源:GameStatusThread.java

示例9: unjailOfflinePlayer

import java.sql.PreparedStatement; //导入方法依赖的package包/类
private void unjailOfflinePlayer(String name)
{
	Connection con = null;
  	try
   	{
   		con = L2DatabaseFactory.getInstance().getConnection();

   		PreparedStatement statement = con.prepareStatement("UPDATE characters SET x=?, y=?, z=?, punish_level=?, punish_timer=? WHERE char_name=?");
   		statement.setInt(1, 17836);
   		statement.setInt(2, 170178);
   		statement.setInt(3, -3507);
   		statement.setInt(4, 0);
   		statement.setLong(5, 0);
   		statement.setString(6, name);

		statement.execute();
		int count = statement.getUpdateCount();
		statement.close();

		if (count == 0)
			_print.println("Character not found!");
		else
			_print.println("Character "+name+" set free.");
   	} catch (SQLException se)
   	{
   		_print.println("SQLException while jailing player");
        if (Config.DEBUG) se.printStackTrace();
   	} finally
   	{
   		try { con.close(); } catch (Exception e) {}
   	}
}
 
开发者ID:L2jBrasil,项目名称:L2jBrasil,代码行数:33,代码来源:GameStatusThread.java

示例10: jailOfflinePlayer

import java.sql.PreparedStatement; //导入方法依赖的package包/类
private void jailOfflinePlayer(L2PcInstance activeChar, String name, int delay)
{
	Connection con = null;
	try
	{
		con = L2DatabaseFactory.getInstance().getConnection();

		PreparedStatement statement = con.prepareStatement("UPDATE characters SET x=?, y=?, z=?, in_jail=?, jail_timer=? WHERE char_name=?");
		statement.setInt(1, -114356);
		statement.setInt(2, -249645);
		statement.setInt(3, -2984);
		statement.setInt(4, 1);
		statement.setLong(5, (delay > 0 ? delay * 60000L : 0));
		statement.setString(6, name);

		statement.execute();
		int count = statement.getUpdateCount();
		statement.close();

		if (count == 0)
			activeChar.sendMessage("Character not found!");
		else
			activeChar.sendMessage("Character "+name+" jailed for "+(delay>0 ? delay+" minutes." : "ever!"));
	} catch (SQLException se)
	{
		activeChar.sendMessage("SQLException while jailing player");
		if (Config.DEBUG) se.printStackTrace();
	} finally
	{
		try { con.close(); } catch (Exception e)
		{
			if (Config.DEBUG)
				e.printStackTrace();
		}
	}
}
 
开发者ID:L2jBrasil,项目名称:L2jBrasil,代码行数:37,代码来源:AdminBan.java

示例11: unjailOfflinePlayer

import java.sql.PreparedStatement; //导入方法依赖的package包/类
private void unjailOfflinePlayer(L2PcInstance activeChar, String name)
{
	Connection con = null;
	try
	{
		con = L2DatabaseFactory.getInstance().getConnection();
		PreparedStatement statement = con.prepareStatement("UPDATE characters SET x=?, y=?, z=?, in_jail=?, jail_timer=? WHERE char_name=?");
		statement.setInt(1, 17836);
		statement.setInt(2, 170178);
		statement.setInt(3, -3507);
		statement.setInt(4, 0);
		statement.setLong(5, 0);
		statement.setString(6, name);
		statement.execute();
		int count = statement.getUpdateCount();
		statement.close();
		if (count == 0)
			activeChar.sendMessage("Character not found!");
		else
			activeChar.sendMessage("Character "+name+" removed from jail");
	} catch (SQLException se)
	{
		activeChar.sendMessage("SQLException while jailing player");
		if (Config.DEBUG) se.printStackTrace();
	} finally
	{
		try
		{
			con.close();
		}
		catch (Exception e)
		{
			if (Config.DEBUG)
				e.printStackTrace();
		}
	}
}
 
开发者ID:L2jBrasil,项目名称:L2jBrasil,代码行数:38,代码来源:AdminBan.java

示例12: executePreparedStatement

import java.sql.PreparedStatement; //导入方法依赖的package包/类
private int executePreparedStatement(PreparedStatement stmt) throws SQLException {
    long startTime = System.currentTimeMillis();
    
    stmt.execute();

    long executionTime = System.currentTimeMillis() - startTime;
    String execTimeStr = SQLExecutionHelper.millisecondsToSeconds(executionTime);
    dataView.setInfoStatusText(NbBundle.getMessage(SQLExecutionHelper.class, "MSG_execution_success", execTimeStr));
    
    return stmt.getUpdateCount();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:12,代码来源:SQLExecutionHelper.java

示例13: banChatOfflinePlayer

import java.sql.PreparedStatement; //导入方法依赖的package包/类
public static void banChatOfflinePlayer(String name, int delay, boolean ban)
{
	int level = 0;
	long value = 0;
	
	if (ban)
	{
		level = L2PcInstance.PunishLevel.CHAT.value();
		value = (delay > 0 ? delay * 60000L : 60000);
	}
	else
	{
		level = L2PcInstance.PunishLevel.NONE.value();
		value = 0;
	}
	
	try (Connection con = L2DatabaseFactory.getInstance().getConnection())
	{
		PreparedStatement statement = con.prepareStatement("UPDATE characters SET punish_level=?, punish_timer=? WHERE char_name=?");
		statement.setInt(1, level);
		statement.setLong(2, value);
		statement.setString(3, name);
		
		statement.execute();
		int count = statement.getUpdateCount();
		statement.close();
	}
	catch (SQLException se)
	{
	}
}
 
开发者ID:Elfocrash,项目名称:L2ACP-api,代码行数:32,代码来源:Helpers.java

示例14: changeCharAccessLevel

import java.sql.PreparedStatement; //导入方法依赖的package包/类
public static boolean changeCharAccessLevel(L2PcInstance targetPlayer, String player, int lvl)
{
	if (targetPlayer != null)
	{
		targetPlayer.setAccessLevel(lvl);
		targetPlayer.logout();
	}
	else
	{
		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
		{
			PreparedStatement statement = con.prepareStatement("UPDATE characters SET accesslevel=? WHERE char_name=?");
			statement.setInt(1, lvl);
			statement.setString(2, player);
			statement.execute();
			int count = statement.getUpdateCount();
			statement.close();
			
			if (count == 0)
			{
				return false;
			}
		}
		catch (SQLException se)
		{				
			return false;
		}
	}
	return true;
}
 
开发者ID:Elfocrash,项目名称:L2ACP-api,代码行数:31,代码来源:Helpers.java

示例15: changeCharacterPosition

import java.sql.PreparedStatement; //导入方法依赖的package包/类
private void changeCharacterPosition(L2PcInstance activeChar, String name)
{
	final int x = activeChar.getX();
	final int y = activeChar.getY();
	final int z = activeChar.getZ();
	try (Connection con = DatabaseFactory.getInstance().getConnection())
	{
		final PreparedStatement statement = con.prepareStatement("UPDATE characters SET x=?, y=?, z=? WHERE char_name=?");
		statement.setInt(1, x);
		statement.setInt(2, y);
		statement.setInt(3, z);
		statement.setString(4, name);
		statement.execute();
		final int count = statement.getUpdateCount();
		statement.close();
		if (count == 0)
		{
			activeChar.sendMessage("Character not found or position unaltered.");
		}
		else
		{
			activeChar.sendMessage("Player's [" + name + "] position is now set to (" + x + "," + y + "," + z + ").");
		}
	}
	catch (SQLException se)
	{
		activeChar.sendMessage("SQLException while changing offline character's position");
	}
}
 
开发者ID:rubenswagner,项目名称:L2J-Global,代码行数:30,代码来源:AdminTeleport.java


注:本文中的java.sql.PreparedStatement.getUpdateCount方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。