说明一下,我用的应用服务器是ibm webshpere 4.0
解决方案 »
- jfreechart柱形图 一个柱子上怎么弄多种颜色
- Spring jdbcTemp事物处理
- hibernate执行update时如何不更新缓存
- 重装了ie后无法打开localhost
- Aop问题,struts+sping拦截不到Action
- 大家帮忙看看这几张图是用什么工具做的?
- 怎么样才成为一个java高手!
- 哪儿有现成封装好的java http协议包下载
- 本人现在是研二学生,想做一个关于P2P方面的课题,请问有这方面的资料吗?[email protected]可以用J2EE吗?基于哪方面应用比较好啊?
- 用tomcat在服务端用xslt解析xml生成html的中文问题!
- 碰到了一个奇怪问题,请帮忙.
- ejb2.0 interface的local/remote的含义是啥
一种是lookup jndi,找出datasource(当然你要事先配置好)
======================================
package Test3; import java.sql.*;
import javax.sql.*;
import javax.naming.*;
import javax.ejb.*; public class Test3SessionBean implements SessionBean { private SessionContext sc = null;
private Context ctx = null;
private DataSource ds = null;
public void ejbCreate() throws CreateException { try {
ctx = new InitialContext();
ds = (DataSource)ctx.lookup("jdbc/db2/HelloWroldDatasource");
}
catch (Exception e) {
System.out.println(e.getMessage());
throw new CreateException();
}
} public void gettest3() throws SQLException {
Connection con = null;
ResultSet rs;
try {
con = ds.getConnection("dingjs", "crystal");
Statement stmt = con.createStatement();
rs = stmt.executeQuery("select * from TEST2");
while (rs.next()) {
int id = rs.getInt("ID");
String firstName = rs.getString("FIRSTNAME");
String lastName = rs.getString("LASTNAME"); System.out.print(id + " " + firstName + " " + lastName);
}
rs.close();
stmt.close();
con.close();
}
catch(SQLException ex) {
System.err.println("SQLException: " + ex.getMessage());
}
}
public void setSessionContext(SessionContext sc) {
this.sc = sc;
}
public void ejbRemove() {}
public void ejbPassivate() {}
public void ejbActivate() {}
}
DataSource ds = (DataSource)ctx.lookup("jdbc/db2/HelloWroldDatasource");
Connection con = ds.getConnection("dingjs", "crystal"); Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("select * from TEST2");
while (rs.next()) {
int id = rs.getInt("ID");
String firstName = rs.getString("FIRSTNAME");
String lastName = rs.getString("LASTNAME");
System.out.print(id + " " + firstName + " " + lastName);
}
rs.close();
stmt.close();
con.close();