概述
package com.digitalchina.work.xlroot.juece.hongguan.jingji;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;
public class JDBCConnection {
public JDBCConnection() {
super();
// TODO Auto-generated constructor stub
}
public static Connection getJdbcConnection(){
Connection con;
Context context;
try {
context = new InitialContext();
DataSource ds = (DataSource) context.lookup("datasourceADP");
con = ds.getConnection();
return con;
} catch (NamingException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
/*try {
Class.forName("oracle.jdbc.driver.OracleDriver");
con = DriverManager.getConnection("jdbc:oracle:thin:@172.20.4.98:1521:adp", "adp", "adp");
return con;
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}*/
return null;
}
}
最后
以上就是温暖蜜蜂为你收集整理的通过jndi得到connection对象的全部内容,希望文章能够帮你解决通过jndi得到connection对象所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复