當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。