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


Java Statement.getUpdateCount方法代码示例

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


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

示例1: execute

import java.sql.Statement; //导入方法依赖的package包/类
public final boolean execute(String sql, Object... args) {
    if (!isConnected()) {
        return false;
    }
    String temp = null;
    try {
        temp = (args != null && args.length != 0) ? String.format(sql, args) : sql;
        if (DEBUG_SQL) {
            System.out.println(temp);
        }
        final Statement statement = createStatement();
        statement.execute(temp);
        final boolean result = statement.getUpdateCount() >= 0;
        statement.close();
        return result;
    } catch (Exception ex) {
        System.err.println("Database: Executing error");
        if (DEBUG) {
            System.err.println("SQL: " + temp);
        }
        ex.printStackTrace();
        return false;
    }
}
 
开发者ID:Panzer1119,项目名称:Supreme-Bot,代码行数:25,代码来源:Database.java

示例2: execute

import java.sql.Statement; //导入方法依赖的package包/类
@Override
public ResultSet execute(Statement statement, String sql) {
	sqlStatementLogger.logStatement( sql );
	try {
		final ResultSet rs;
		try {
			jdbcCoordinator.getTransactionCoordinator().getTransactionContext().startStatementExecution();
			if ( !statement.execute( sql ) ) {
				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

示例3: test

import java.sql.Statement; //导入方法依赖的package包/类
protected boolean test(Statement aStatement) {

        try {
            try {

                //execute the SQL
                aStatement.execute(getSql());
            } catch (SQLException s) {
                throw new Exception("Expected an update count of "
                                    + getCountWeWant()
                                    + ", but got the error: "
                                    + s.getMessage());
            }

            if (aStatement.getUpdateCount() != getCountWeWant()) {
                throw new Exception("Expected an update count of "
                                    + getCountWeWant()
                                    + ", but got an update count of "
                                    + aStatement.getUpdateCount() + ".");
            }
        } catch (Exception x) {
            message = x.toString();

            return false;
        }

        return true;
    }
 
开发者ID:tiweGH,项目名称:OpenDiabetes,代码行数:29,代码来源:TestUtil.java

示例4: showQueryResult

import java.sql.Statement; //导入方法依赖的package包/类
/**
 * Show the result of given query.
 * 
 * @param conn
 *            The connection to use for querying the data source.
 * @param sql
 *            The SQL query to use for querying the data source.
 * @throws SQLException
 *             if error happens when executing the query.
 */
private static void showQueryResult(Connection conn, String sql)
		throws SQLException {
	System.out.println("Executing SQL query: " + sql);
	Statement stmt = null;
	try {
		stmt = conn.createStatement();
		boolean isResultSet = stmt.execute(sql);
		boolean hasMoreResult = true;
		while (hasMoreResult) {
			if (isResultSet) {
				ResultSet rs = null;
				try {
					rs = stmt.getResultSet();
					printResultSet(rs);
				} finally {
					if (rs != null) {
						rs.close();
					}
				}
			} else {
				int rowCount = stmt.getUpdateCount();
				if (rowCount == -1) {
					hasMoreResult = false;
				} else {
					System.out.println(String.format(
							"Query OK, %d row affected.", rowCount));
				}
			}
			isResultSet = stmt.getMoreResults();
		}
	} finally {
		if (stmt != null) {
			stmt.close();
		}
	}
}
 
开发者ID:kineticadb,项目名称:kinetica-client-jdbc,代码行数:47,代码来源:JDBCSample.java

示例5: test

import java.sql.Statement; //导入方法依赖的package包/类
protected boolean test(Statement aStatement) {

        try {
            try {

                //execute the SQL
                aStatement.execute(getSql());
            } catch (SQLException s) {
                throw new Exception("Expected an update count of "
                                    + getCountWeWant()
                                    + ", but got the error: "
                                    + s.getMessage());
            }

            if (aStatement.getUpdateCount() != getCountWeWant()) {
                throw new Exception("Expected an update count of "
                                    + getCountWeWant()
                                    + ", but got an update count of "
                                    + aStatement.getUpdateCount() + ".");
            }
        } catch (Exception x) {
            message = x.getMessage();

            return false;
        }

        return true;
    }
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:29,代码来源:TestUtil.java

示例6: executeUpdate

import java.sql.Statement; //导入方法依赖的package包/类
public static int[] executeUpdate(Connection conn, String[] sqls) throws Exception {
	boolean isShowSql = false;
	List<String> sqlList = new ArrayList<String>();
	for (String sql : sqls) {
		if (StringUtils.hasText(sql)) {
			sqlList.add(sql);
		}
	}
	String[] sqlArray = sqlList.toArray(new String[] {});
	if (isShowSql) {
		for (String s : sqlArray) {
			System.out.println(s);
		}
	}
	Statement st = null;
	int[] rowsAffected = new int[] { sqlArray.length };
	try {
		conn.setAutoCommit(true);
		st = conn.createStatement();
		if (DbJdbcUtils.supportsBatchUpdates(conn)) {
			for (String currentSql : sqlArray) {
				st.addBatch(currentSql);
			}
			rowsAffected = st.executeBatch();
		} else {
			for (int i = 0; i < sqlArray.length; i++) {
				if (!st.execute(sqlArray[i])) {
					rowsAffected[i] = st.getUpdateCount();
				}
			}
		}
	} catch (SQLException e) {
		throw new SQLException(e);
	} finally {
		DbJdbcUtils.closeStatement(st);
	}
	return rowsAffected;
}
 
开发者ID:bsteker,项目名称:bdf2,代码行数:39,代码来源:DbJdbcUtils.java

示例7: executeSqlStatement

import java.sql.Statement; //导入方法依赖的package包/类
/**
 * @param dbstmt        Database sql-Statement
 * @param statement     sql-Statement
 * @throws Exception    SQL-Exception while executing sqlstatement
 */
private void executeSqlStatement (Statement dbstmt, String statement)
        throws Exception {

    try {
        boolean isResultSet = dbstmt.execute(statement);  //only allows SQL INSERT, UPDATE or DELETE
        if(isResultSet) {
            ResultSet rs=dbstmt.getResultSet();
            StringBuffer res=new StringBuffer();
            int colCount=rs.getMetaData().getColumnCount();
            String sep="";
            while(rs.next()) {
                for(int i=1;i<=colCount;i++) {
                    String value=rs.getString(i);
                    if(value!=null) {
                        res.append(sep);
                        res.append(value);
                        sep=" ";
                    }
                }
                if(res.length()>0) {
                    log.lifecycle(taskName + ": " + res.toString());
                }
                res.setLength(0);
                sep="";
            }
        }else {
            int modifiedLines=dbstmt.getUpdateCount();
            if (modifiedLines==1) {
                log.lifecycle(taskName + ": " + modifiedLines + " Line has been modified.");
            } else if (modifiedLines>1) {
                log.lifecycle(taskName +": " + modifiedLines + " Lines have been modified.");
            } else if (modifiedLines<1){
                log.lifecycle(taskName + ": No Line has been modified.");
            }
        }


    } catch (SQLException ex) {
        throw new SQLException("Error while executing the sqlstatement. " + ex.getMessage());
    } finally {
        dbstmt.close();
    }
}
 
开发者ID:sogis,项目名称:gretl,代码行数:49,代码来源:SqlExecutorStep.java


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