JAVA之Context
???数据库连接
------------------------------------------------------------------------
public Connection getConnectionforGIS() throws Exception {
Connection conn;
Context ctx = (Context) new InitialContext();
if (ctx == null) {
throw new Exception("Context is null.");
}else{
DataSource ds = (DataSource) ctx.lookup(JNDI_NameOfGIS); // ***???????
if (ds == null) {
throw new Exception("DataSource is null.");
}else{
conn = ds.getConnection();
System.out.println("get the connection of "+JNDI_NameOfGIS);
}
if (conn.isClosed()) {
throw new Exception("Jndi Connection is closed.");
}else{
}
}
return conn;
}