📄 getdatasource.java
字号:
// ==================== Program Discription ==========================
// 程序名称:示例13-5 : GetDataSource.java
// 程序目的:从命名服务中查询DataSource对象
// ==============================================================
import java.util.Hashtable ;
import javax.naming.* ;
import java.sql.* ;
import javax.sql.* ;
public class GetDataSource
{
public GetDataSource()
{
try {
// set up the JNDI context
Hashtable env = new Hashtable() ;
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.fscontext.RefFSContextFactory") ;
Context ctx = new InitialContext(env) ;
// lookup the object in JNDI Context
DataSource ds = (DataSource)ctx.lookup("jdbc/ datasource ") ;
// get a database connection
Connection con = ds.getConnection() ;
con.close();
}
catch(Exception e ) {
e.printStackTrace();
}
}
public static void main (String args[]){
new GetDataSource() ;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -