⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 getconnection.java

📁 THIS IS A FINANCIAL BANK APPLICATION
💻 JAVA
字号:
package ma.bmce.tools;

import java.sql.Connection;
import java.sql.SQLException;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;

public class GetConnection {

	/*
	 * il faut modifier: set the "Debug" property to "false" in the
	 * CachedConnectionManager mbean configuration, in the jbossjca-service.xml file
	 */

	public Connection openConnection() {

		DataSource ds = null;
		Connection conn = null;

		try {

			InitialContext ic = new InitialContext();

			ds = (DataSource) ic.lookup("java:/PcardgDS");

		} catch (NamingException ex) {

			throw new IllegalStateException(ex);

		}

		try {
			if (ds != null) {
				System.out.println("ds non null");
				conn = ds.getConnection();
				System.out.println("connexion ok");

			} else
				System.out.println("ds  null");

			return conn;

		} catch (SQLException ex) {

			throw new IllegalStateException(ex);

		}

	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -