// Obtain our environment naming context
Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
// Look up our data source
DataSource ds = (DataSource)
envCtx.lookup("jdbc/EmployeeDB");
// Allocate and use a connection from the pool
Connection conn = ds.getConnection();
... use this connection to access the database ...
conn.close();
如何通过jndi连接数据源
最新推荐文章于 2018-11-06 09:44:39 发布
本文介绍了一种使用Java进行数据库连接的方法。首先通过获取环境命名上下文初始化上下文,然后查找并定位到特定的数据源,接着从连接池中分配并使用连接来访问数据库。
850

被折叠的 条评论
为什么被折叠?



