说明一下,我用的应用服务器是ibm webshpere 4.0
解决方案 »
- JSON的问题,挣扎了好久了
- spring+struts2 用jetty作为内嵌服务器,访问action路径出错
- windows2003 Apach2.2+Tomcat6.0 LoadBlance 问题
- 相同方法名,参数类型不同,传NULL参数。先调用谁?
- 24小时结帖~~form数据不能传到action那里去~
- eclipse和myeclipse里spring配置文件为什么放的位置不同
- 如何在Jbuilder中使用类的继承?
- jbuilder8+weblogic+sql server环境配置是怎么配置的?
- webservice设置的http请求头丢失
- 我用的是springmvc框架,为什么在tomcat 的server.xml里面设置了URIEncoding="UTF-8" get提交时还是会乱码
- 碰到了一个奇怪问题,请帮忙.
- 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();