當前位置: 首頁>>代碼示例>>Java>>正文


Java DbUtils.closeQuietly方法代碼示例

本文整理匯總了Java中org.apache.commons.dbutils.DbUtils.closeQuietly方法的典型用法代碼示例。如果您正苦於以下問題:Java DbUtils.closeQuietly方法的具體用法?Java DbUtils.closeQuietly怎麽用?Java DbUtils.closeQuietly使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.commons.dbutils.DbUtils的用法示例。


在下文中一共展示了DbUtils.closeQuietly方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: main

import org.apache.commons.dbutils.DbUtils; //導入方法依賴的package包/類
public static void main(String[] args) {
	Connection conn = null;

	final String url = "jdbc:h2:./target/test;AUTO_SERVER=TRUE";
	final String driver = "org.h2.Driver";
	final String usr = "sa";
	final String pwd = "";

	try {
		DbUtils.loadDriver(driver);
		conn = DriverManager.getConnection(url, usr, pwd);
		QueryRunner query = new QueryRunner();
		List<Map<String, Object>> mapList = (List<Map<String, Object>>) query
				.query(conn, "select * from user", new MapListHandler());
		for (int i = 0; i < mapList.size(); i++) {
			Map<String, Object> map = (Map<String, Object>) mapList.get(i);
			System.out.println("------> " + map.get("userId") + "\t"
					+ map.get("firstName") + "\t" + map.get("emailId"));
		}
	} catch (SQLException se) {
		se.printStackTrace();
	} finally {
		DbUtils.closeQuietly(conn);
	}
}
 
開發者ID:v5developer,項目名稱:maven-framework-project,代碼行數:26,代碼來源:DbUtilsMapListHandler.java

示例2: getConnection

import org.apache.commons.dbutils.DbUtils; //導入方法依賴的package包/類
public static Connection getConnection(String dbname) throws SQLException {
    String dbpath = getDbPath(dbname);
    String jdbcurl = "jdbc:h2:file:" + dbpath + ";DB_CLOSE_ON_EXIT=FALSE";
    LOG.info("connect jdbcurl = {}", jdbcurl);
    Connection conn = DriverManager.getConnection(jdbcurl, "sa", "");

    DataSource ds = new CustomFlywayDataSource(new PrintWriter(System.out), conn);
    Flyway flyway = new Flyway();
    flyway.setDataSource(ds);
    // explicitly set h2db driver loaded (= including this jar file) class loader
    flyway.setClassLoader(conn.getClass().getClassLoader());
    flyway.migrate();
    LOG.info("db[{}] migration success", dbname);

    // may be already closed -> reconnect.
    DbUtils.closeQuietly(conn);
    conn = DriverManager.getConnection(jdbcurl, "sa", "");

    return conn;
}
 
開發者ID:SecureSkyTechnology,項目名稱:burpextender-proxyhistory-webui,代碼行數:21,代碼來源:DataStore.java

示例3: runLibraryScript

import org.apache.commons.dbutils.DbUtils; //導入方法依賴的package包/類
private long runLibraryScript(final String scriptSQL, final Connection conn) throws DeployException {
runScript(scriptSQL, conn);
PreparedStatement stmt = null;
ResultSet results = null;
try {
    stmt = conn.prepareStatement("SELECT LAST_INSERT_ID() FROM lams_learning_library");
    results = stmt.executeQuery();
    if (results.next()) {
	return results.getLong("LAST_INSERT_ID()");
    } else {
	throw new DeployException("Could not get learning_library_id");
    }
} catch (SQLException sqlex) {
    throw new DeployException("Failed to run learning library script", sqlex);
} finally {
    DbUtils.closeQuietly(stmt);
    DbUtils.closeQuietly(results);
}

   }
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:21,代碼來源:ToolDBDeployTask.java

示例4: runToolInsertScript

import org.apache.commons.dbutils.DbUtils; //導入方法依賴的package包/類
private long runToolInsertScript(final String scriptSQL, final Connection conn) throws DeployException {
runScript(scriptSQL, conn);
PreparedStatement stmt = null;
ResultSet results = null;
try {
    stmt = conn.prepareStatement("SELECT LAST_INSERT_ID() FROM lams_tool");
    results = stmt.executeQuery();
    if (results.next()) {
	return results.getLong("LAST_INSERT_ID()");
    } else {
	throw new DeployException("Could not get learning_library_id");
    }
} catch (SQLException sqlex) {
    throw new DeployException("Failed to run tool insert script", sqlex);
} finally {
    DbUtils.closeQuietly(stmt);
    DbUtils.closeQuietly(results);
}

   }
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:21,代碼來源:ToolDBDeployTask.java

示例5: queryTool

import org.apache.commons.dbutils.DbUtils; //導入方法依賴的package包/類
public String queryTool(String toolSig, String column) {
Connection conn = getConnection();
PreparedStatement stmt = null;
ResultSet results = null;
try {
    stmt = conn
	    .prepareStatement("select " + column + " from lams_tool where tool_signature= \"" + toolSig + "\"");
    System.out.println("SQL stmt: " + stmt);
    results = stmt.executeQuery();

    if (results.first()) {
	return results.getString(column);

    }
} catch (SQLException se) {

    throw new DeployException("Could not get entry from lams_tool: " + column + "\n" + se.getMessage());

} finally {
    DbUtils.closeQuietly(stmt);
}
return "ERROR";
   }
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:24,代碼來源:ToolDBUpdater.java

示例6: testDeploy

import org.apache.commons.dbutils.DbUtils; //導入方法依賴的package包/類
@Test
public void testDeploy() throws Exception {
    getAppContext.valueOf(1)
            .cleanEnvironment()
            .deploy();

    // ensuring that we can modify
    DbDeployerAppContext dbDeployerAppContext = getAppContext.valueOf(2);
    dbDeployerAppContext
            .cleanEnvironment()
            .setupEnvInfra()
            .deploy();

    JdbcHelper jdbc = new JdbcHelper();

    Connection conn = ds.getConnection();
    try {
        List<Map<String, Object>> results = jdbc.queryForList(conn, "select * from " + dbDeployerAppContext.getEnvironment().getPhysicalSchema("schema1") + ".TABLE_A order by a_id");
        assertEquals(3, results.size());
        this.validateResults(results.get(0), 2, 3, "fasdfasd", "2013-02-02 11:11:11.65432", 9);
        this.validateResults(results.get(1), 3, 4, "ABC", null, 9);
        this.validateResults(results.get(2), 4, 2, "ABC", "2012-01-01 12:12:12", null);
    } finally {
        DbUtils.closeQuietly(conn);
    }
}
 
開發者ID:goldmansachs,項目名稱:obevo,代碼行數:27,代碼來源:PostgreSqlDeployerIT.java

示例7: runLibraryScript

import org.apache.commons.dbutils.DbUtils; //導入方法依賴的package包/類
/**
    * Runs the sql statements and will return the last inserted id from the particular
    * table.
    * 
    * @param scriptSQL
    *            The sql to run
    * @param conn
    * @param tablename
    *            The table which to query for the last inserted id.
    * @return the last inserted id from <code>tablename</code>
    * @throws DeployException
    */
   private long runLibraryScript(final String scriptSQL, final Connection conn, String tablename)
    throws DeployException {
runScript(scriptSQL, conn);
PreparedStatement stmt = null;
ResultSet results = null;
try {
    stmt = conn.prepareStatement("SELECT LAST_INSERT_ID() FROM " + tablename);
    results = stmt.executeQuery();
    if (results.next()) {
	return results.getLong("LAST_INSERT_ID()");
    } else {
	throw new DeployException("Could not get the last inserted id from table " + tablename);
    }
} catch (SQLException sqlex) {
    throw new DeployException("Failed to run learning library script", sqlex);
} finally {
    DbUtils.closeQuietly(stmt);
    DbUtils.closeQuietly(results);
}

   }
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:34,代碼來源:LibraryDBDeployTask.java

示例8: main

import org.apache.commons.dbutils.DbUtils; //導入方法依賴的package包/類
public static void main(String[] args) 
{
	try
	{
		EnaValidator enaValidator = new EnaValidator();
		enaValidator.init(args,null);
		enaValidator.initValidator();
		int failedCount =enaValidator.validateFiles();
		
		if(failedCount==0)
			System.exit(0);
		if(failedCount>0)
			System.exit(3);
	}
	catch (Exception e)
	{
		e.printStackTrace();
		System.exit(1);
		
	}
	finally
	{
		DbUtils.closeQuietly(con);

	}
}
 
開發者ID:enasequence,項目名稱:sequencetools,代碼行數:27,代碼來源:EnaValidator.java

示例9: getRecordCount

import org.apache.commons.dbutils.DbUtils; //導入方法依賴的package包/類
private int getRecordCount(int validRecordValue1, int validRecordValue2) throws HarvestException
{
	PreparedStatement pstmt=null;
	ResultSet rs = null;
	try {
		pstmt = this.dbConnection.prepareStatement(
				String.format(GET_RECORD_COUNT, this.dbTableName));
		pstmt.setInt(1, validRecordValue1);
		pstmt.setInt(2, validRecordValue2);
		rs = pstmt.executeQuery();
		rs.first();
		return rs.getInt(1);
	} catch (SQLException e) {
		throw new HarvestException(Config.Exceptions.RESOURCE_DEPENDENCY_ERROR_CODE,
				"Trouble getting record count from workspace DB", e );
	}
	finally
	{	
		DbUtils.closeQuietly(rs);
		DbUtils.closeQuietly(pstmt);
	}
}
 
開發者ID:NCAR,項目名稱:dls-repository-stack,代碼行數:23,代碼來源:DBWorkspace.java

示例10: dropTable

import org.apache.commons.dbutils.DbUtils; //導入方法依賴的package包/類
/**
 * try to drop the session table
 * @throws HarvestException
 */
public void dropTable() throws HarvestException
{
	if (this.dbConnection==null)
		this.dbConnection = this.getConnection();
	if (this.dbConnection!=null)
	{
		Statement stmt = null;
		try
		{
			stmt = this.dbConnection.createStatement();
			stmt.execute(String.format(DROP_TABLE_STMT, this.dbTableName));
		}
		catch (SQLException e) {
			// table doesn't exist, doesn't matter keep on chugging
		}
		finally
		{
			DbUtils.closeQuietly(stmt);
		}
	}
	
}
 
開發者ID:NCAR,項目名稱:dls-repository-stack,代碼行數:27,代碼來源:DBWorkspace.java

示例11: log

import org.apache.commons.dbutils.DbUtils; //導入方法依賴的package包/類
/**
 * Main log method that everything else calls, This puts the message into the db
 * @param msg
 * @param level
 */
private void log(String msg, String level)
{
	PreparedStatement insert_log_pstmt=null;
	try {
		insert_log_pstmt = this.dbConnection.prepareStatement(
				LOG_INSERT_STMT);
		insert_log_pstmt.setString(1, this.uuid);
		insert_log_pstmt.setString(2, msg);
		insert_log_pstmt.setString(3, level);
		insert_log_pstmt.execute();
		insert_log_pstmt.close();
	} catch (SQLException e) {
		// TODO we got some massive issues, what to do if we can't log to db
		e.printStackTrace();
	}
	finally
	{
		DbUtils.closeQuietly(insert_log_pstmt);
	}
	
}
 
開發者ID:NCAR,項目名稱:dls-repository-stack,代碼行數:27,代碼來源:DBLogger.java

示例12: cleanupPreparedStatments

import org.apache.commons.dbutils.DbUtils; //導入方法依賴的package包/類
/**
 * Closes up all the cached prepared statements to release all locks and free some
 * memory up. Might be unnecessary but i helped with locks during development
 */
private void cleanupPreparedStatments()
{
	DbUtils.closeQuietly(this.insertURIPstmt);
	this.insertURIPstmt = null;
	DbUtils.closeQuietly(this.populateRecordPstmt);
	this.populateRecordPstmt = null;
	DbUtils.closeQuietly(this.updateHandlesPstmt);
	this.updateHandlesPstmt = null;
	
	for(PreparedStatement pstmt:this.updateRecordPstmts.values())
	{
		DbUtils.closeQuietly(pstmt);
	}
	this.updateRecordPstmts = new HashMap<String, PreparedStatement>();
}
 
開發者ID:NCAR,項目名稱:dls-repository-stack,代碼行數:20,代碼來源:DBWorkspace.java

示例13: removeSessionHarvestedRecords

import org.apache.commons.dbutils.DbUtils; //導入方法依賴的package包/類
/**
 * Delete a specified session of harvested records
 * @param setSpec
 * @param sessionId
 * @throws HarvestException
 */
public void removeSessionHarvestedRecords(String setSpec, String sessionId) throws HarvestException
{
	PreparedStatement pstmt=null;
	try {
		pstmt = this.harvestConnection.prepareStatement(REMOVE_HARVESTED_RECORDS_STMT);
		pstmt.setString(1, setSpec);
		pstmt.setString(2, sessionId);
		pstmt.execute();

	} catch (SQLException e) {
		throw new HarvestException(Config.Exceptions.RESOURCE_DEPENDENCY_ERROR_CODE,
			String.format("Trouble removing old session from harvested " +
				"records db. SessionId:%s  SetSpec: %s",setSpec, sessionId), e );
	}
	finally
	{	
		DbUtils.closeQuietly(pstmt);
	}
}
 
開發者ID:NCAR,項目名稱:dls-repository-stack,代碼行數:26,代碼來源:HarvestedRecordsDB.java

示例14: getDbcode

import org.apache.commons.dbutils.DbUtils; //導入方法依賴的package包/類
@Override
public String getDbcode(String prefix) throws SQLException {
	if(prefix==null)
		return null;
	 String sql=	"select dbcode from cv_database_prefix where prefix= ?";
	  ResultSet rs = null;
	  PreparedStatement ps = null;
		try
		{
			ps = connection.prepareStatement(sql);
			ps.setString(1, prefix);
			rs = ps.executeQuery();
			if(rs.next())
			{
    			return rs.getString(1);
			}
		}finally
		{
			DbUtils.closeQuietly(rs);
			DbUtils.closeQuietly(ps);
		}
		
		
	  return null;
}
 
開發者ID:enasequence,項目名稱:sequencetools,代碼行數:26,代碼來源:EntryDAOUtilsImpl.java

示例15: getSequenceLength

import org.apache.commons.dbutils.DbUtils; //導入方法依賴的package包/類
@Override
public Long getSequenceLength(String accession) throws SQLException
{
	ResultSet rs = null;
	PreparedStatement ps = null;
	try
	{
		ps = connection.prepareStatement("select seqlen from bioseq where sequence_acc=? or seq_accid=?");
		ps.setString(1,accession);
		ps.setString(2, accession);
		rs = ps.executeQuery();
		if (rs.next())
		{
			return rs.getLong(1);
		}

		return 0L;
	} finally
	{
		DbUtils.closeQuietly(rs);
		DbUtils.closeQuietly(ps);
	}
}
 
開發者ID:enasequence,項目名稱:sequencetools,代碼行數:24,代碼來源:EntryDAOUtilsImpl.java


注:本文中的org.apache.commons.dbutils.DbUtils.closeQuietly方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。