67,516
社区成员
发帖
与我相关
我的任务
分享
public CachedRowSet GetDataSet(String pSQL)
{
//定义离线数据集
CachedRowSet rs = null;
try
{
/**
* 从服务器连接池中初始化数据库连接
*/
rs = new CachedRowSetImpl();
rs.setDataSourceName("jdbc/OracleConn");
rs.setCommand(pSQL);
rs.execute();
} catch (SQLException ex) {
Logger.getLogger(NewSessionBean.class.getName()).log(Level.SEVERE, null, ex);
}
return rs;
}
@WebMethod(operationName = "GetDataSet")
public String GetDataSet(@WebParam(name = "pStr")
String pStr) {
String lResult = "";
ejb.NewSessionRemote EjbRef = GetEjbObject("127.0.0.1", "3700", "DBEjb");
RowSet rs = EjbRef.GetDataSet(pStr);
try
{
while(rs.next())
lResult += rs.getString(1);
}
catch(java.sql.SQLException err)
{
err.printStackTrace();
}
return lResult;
}
private ejb.NewSessionRemote GetEjbObject(String pIP, String pPort, String pJndi)
{
ejb.NewSessionRemote lEjbRef = null;
try {
Properties props = new Properties();
props.setProperty("java.naming.factory.initial", "com.sun.enterprise.naming.SerialInitContextFactory");
props.setProperty("java.naming.factory.url.pkgs", "com.sun.enterprise.naming");
props.setProperty("java.naming.factory.state", "com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl");
props.setProperty("org.omg.CORBA.ORBInitialHost", pIP);
props.setProperty("org.omg.CORBA.ORBInitialPort", pPort);
InitialContext ctx = new InitialContext(props);
lEjbRef = (ejb.NewSessionRemote) ctx.lookup(pJndi);
} catch (NamingException ex) {
Logger.getLogger(NewWebService.class.getName()).log(Level.SEVERE, null, ex);
}
return lEjbRef;
}