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


Java PreparedStatement.getMoreResults方法代码示例

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


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

示例1: getTotal

import java.sql.PreparedStatement; //导入方法依赖的package包/类
/**
 * 得到结果集总数
 * @param ps
 * @return
 * @throws SQLException
 */
private long getTotal(PreparedStatement ps) throws SQLException {
 long total=-1;
 ResultSet rs=null;
 ResultSetMetaData rsmd=null;
 String columnName=null;
 
 while(ps.getMoreResults()){
  rs= ps.getResultSet();
  	  rsmd = rs.getMetaData();
        for (int i = 0, n = rsmd.getColumnCount(); i < n; i++) {
      	  columnName=rsmd.getColumnLabel(i + 1);
      	  if(columnName.equalsIgnoreCase(COLUMN_TOTAL_NAME)){
      		  while (rs.next()) {
      			  total=rs.getLong(columnName);
    	  }
      		  break;
      	  }
        }
    }
 return total;
}
 
开发者ID:endend20000,项目名称:mybatisx,代码行数:28,代码来源:DefaultSqlRunner.java

示例2: 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

示例3: executeResourceScript

import java.sql.PreparedStatement; //导入方法依赖的package包/类
public void executeResourceScript(String resourceFilename) {
    try (InputStream in = getClass().getClassLoader().getResourceAsStream(resourceFilename);
         BufferedReader reader = new BufferedReader(new InputStreamReader(in))) {

        // TODO: must be a nicer way of doing this!
        ArrayList<String> sqls = new ArrayList<String>();
        String insql = "";
        String line = null;
        while ((line = reader.readLine()) != null) {
            insql += line + "\n";
            if (line.endsWith(";")) {
                sqls.add(insql);
                insql = "";
            }
        }
        for (String sql: sqls) {
            PreparedStatement st = conn.prepareStatement(sql);
            boolean results = st.execute();
            while (results) {
                results = st.getMoreResults();
            }
            st.close();
        }

    } catch (IOException x) {
        x.printStackTrace();
    } catch (SQLException e) {
        e.printStackTrace();
    }
}
 
开发者ID:toshiapp,项目名称:toshi-headless-client,代码行数:31,代码来源:SqliteStore.java

示例4: insert

import java.sql.PreparedStatement; //导入方法依赖的package包/类
/**
 * Persist an object, using a natively generated identifier
 */
public Serializable insert(Object[] fields, boolean[] notNull, String sql, Object object, SessionImplementor session) 
throws HibernateException {
	
	if ( log.isTraceEnabled() ) {
		log.trace("Inserting entity: " + getClassName() + " (native id)");
		if ( isVersioned() ) log.trace( "Version: " + Versioning.getVersion(fields, this) );
	}
	
	boolean useGetGeneratedKeys = session.getFactory().isGetGeneratedKeysEnabled();
	
	try {
		
		//TODO: refactor all this stuff up to AbstractEntityPersister:
		String insertSelectSQL = useGetGeneratedKeys ? 
			null : 
			getDialect().appendIdentitySelectToInsert(sql);
		if (insertSelectSQL != null) {
			
			//use one statement to insert the row and get the generated id
			PreparedStatement insertSelect = session.getBatcher().prepareStatement(insertSelectSQL);
			try {
				dehydrate(null, fields, notNull, insertSelect, session);
				if ( !insertSelect.execute() ) {
					while ( !insertSelect.getMoreResults() );
				}
				return getGeneratedIdentity( object, session, insertSelect.getResultSet() );
			}
			finally {
				session.getBatcher().closeStatement(insertSelect);
			}
			
		} 
		else {
			
			//do the insert
			PreparedStatement statement = session.getBatcher().prepareStatement(sql, useGetGeneratedKeys);
			try {
				dehydrate(null, fields, notNull, statement, session);
				statement.executeUpdate();
				if (useGetGeneratedKeys) {
					return getGeneratedIdentity( object, session, GetGeneratedKeysHelper.getGeneratedKey(statement) );
				}
			}
			finally {
				session.getBatcher().closeStatement(statement);
			}
			
			//fetch the generated id in a separate query
			PreparedStatement idselect = session.getBatcher().prepareStatement( sqlIdentitySelect() );
			try {
				return getGeneratedIdentity( object, session, idselect.executeQuery() );
			}
			finally {
				session.getBatcher().closeStatement(idselect);
			}
			
		}
		
	}
	catch (SQLException sqle) {
		throw convert( sqle, "could not insert: " +  MessageHelper.infoString(this) );

	}
	
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:69,代码来源:EntityPersister.java


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