📄 getconnection.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 + -