WebSphere Application Server, Version 6.1   
             オペレーティング・システム: AIX , HP-UX, Linux, Solaris, Windows, Windows Vista

             目次と検索結果のパーソナライズ化

例: データ・アクセス例外の処理 - ConnectionWaitTimeoutException (JDBC API 用)

このコード例は、WebSphere Application Server が、 JDBC アプリケーションに ConnectionWaitTimeout 例外を発行する条件を指定す る方法を示しています。

ConnectionWaitTimeout 例外がキャッチされた場合は常に、 リカバリーに関して行うべきことはほとんどありません。

	public void test1() {
		java.sql.Connection conn = null;
		java.sql.Statement stmt = null;
		java.sql.ResultSet rs = null;

		try {
			// Look for datasource
			java.util.Properties props = new java.util.Properties();
			props.put(
				javax.naming.Context.INITIAL_CONTEXT_FACTORY,
				"com.ibm.websphere.naming.WsnInitialContextFactory");
			ic = new javax.naming.InitialContext(props);
			javax.sql.DataSource ds1 = (javax.sql.DataSource) ic.lookup(jndiString);

			// Get Connection.
			conn = ds1.getConnection();
			stmt = conn.createStatement();
			rs = stmt.executeQuery("select * from mytable where this = 54");
		}
		catch (com.ibm.websphere.ce.cm.ConnectionWaitTimeoutException cwte) {
			//notify the user that the system could not provide a
			//connection to the database.  This usually happens when the
			//connection pool is full and there is no connection
			//available for to share.
		}
		catch (java.sql.SQLException sqle) {
			// handle other database problems.
		}
		finally {
			if (rs != null)
				try {
					rs.close();
				}
				catch (java.sql.SQLException sqle1) {
				}
			if (stmt != null)
				try {
					stmt.close();
				}
				catch (java.sql.SQLException sqle1) {
				}
         if (conn != null)
				try {
					conn.close();
				}
				catch (java.sql.SQLException sqle1) {
				}
		}
	}




関連概念
データ・ソース
接続プール
関連資料
接続プール設定
参照トピック    

ご利用条件 | フィードバック

最終更新: Jan 21, 2008 5:05:53 PM EST
http://publib.boulder.ibm.com/infocenter/wasinfo/v6r1/index.jsp?topic=/com.ibm.websphere.base.doc/info/aes/ae/rdat_conwto.html