本文整理汇总了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;
}
示例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" );
}
}
示例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();
}
}
示例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) );
}
}