在exoplatform中使用Tomcat的数据源

阅读更多

首先在你的context里面配置数据库

1这是一个访问Hypersonic的例子




factory
org.apache.commons.dbcp.BasicDataSourceFactory

maxActive10
maxIdle10
maxWait50000
usernamesa
password
driverClassNameorg.hsqldb.jdbcDriver
urljdbc:hsqldb:file:../resource/sfgl

2 这是访问oracle的



factory
org.apache.commons.dbcp.BasicDataSourceFactory

maxActive100
maxIdle30
maxWait10000
usernameSYSTEM
passwordMANAGER
driverClassNameoracle.jdbc.driver.OracleDriver
urljdbc:oracle:thin:@ibmserver:1521:ORCL
这里的ORCL为SID,注意大小写,用大写
程序中使用数据源的方法
static public class ViewJqfkActionListener extends ExoActionListener {
public void execute(ExoActionEvent event) throws Exception {
String yhh = event.getParameter(OBJECTID);
UIListYhda uiList = (UIListYhda) event.getComponent();
UIJqfk uiJqfk = (UIJqfk) uiList.getSibling(UIJqfk.class);
List list = new ArrayList();
Jqfk j;
Connection conn =
uiList.service_.getDataSource("WaterDS").getConnection();
try {
Statement stmt =
conn.createStatement(
ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
String sql =
"select * from ZLS.JQFK where YHH = '" + yhh + "' ";
ResultSet rs = stmt.executeQuery(sql);
while (rs.next()) {
j = new Jqfk();
j.setYhh(rs.getString("YHH"));
j.setYhm(rs.getString("YHM"));
j.setYsl(rs.getString("YSL"));
j.setZje(rs.getString("ZJE"));
j.setCbqk(rs.getString("CBQK"));
j.setJqrq(rs.getDate("JQRQ"));
j.setHs(rs.getString("HS"));
j.setHsrq(rs.getDate("HSRQ"));
list.add(j);
}
//rs.close();
//stmt.close();
//conn.close();
uiJqfk.setData(list);
uiList.setRenderedSibling(UIJqfk.class);
} catch (SQLException e) {
e.printStackTrace();
} finally {
conn.close();
}
}
}
注意,这里只要关闭conn就可以了,不要关闭rs和stmt
另外,显示的时候一定要用
static private Formater ft_ = Formater.getFormater(null) ;
w.write(ft_.format(y.getYhch()));
来防止数据库该字段有异常


Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=367849


你可能感兴趣的:(Tomcat,Oracle,JDBC,SQL,HSQLDB)