bmp得find问题? 我觉得问题可能出在你的doLoad方法里,请确保你的doLoad方法中用到的主键是从EJBContext里取到的。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 这是我的ejbload方法,我的数据肯定提交了,用的是jboss+mysql,数据库里面查了,有数据。只要不重新部署或重启ejb容器,刚才提交过的数据重新启动客户端用findbyprimary()也好用,但是重启了或重新部署,findbyprimary也不好用,数据都提交了,不明白是什么问题。public void ejbLoad() { /**@todo Complete this method*/ personId = (String)entityContext.getPrimaryKey(); System.out.println(personId); Connection conn = null; PreparedStatement ps = null; ResultSet rs = null; try { conn = getConnection(); ps = conn.prepareStatement( "SELECT name, phone, email FROM person WHERE personId = ?"); ps.setString(1, personId); rs = ps.executeQuery(); if (!rs.next()) throw new NoSuchEntityException(); name = rs.getString(1); phone = rs.getString(2); email = rs.getString(3); // set the modified flag to false after loading the data isModified = false; } catch (SQLException ex) { throw new EJBException(ex); } finally { cleanUp(conn, ps, rs); } }-------------------ejbfindbyprimary---------public PersonPK ejbFindByPrimaryKey(PersonPK pk) throws FinderException { /**@todo Complete this method*/ Connection conn = null; PreparedStatement ps = null; ResultSet rs = null; try { conn = getConnection(); ps = conn.prepareStatement( "SELECT 1 FROM person WHERE personId = ?"); ps.setString(1, pk.personId); rs = ps.executeQuery(); if (rs.next()) { System.out.println("return pk"); return pk; } else { throw new ObjectNotFoundException(); } } catch (SQLException ex) { throw new EJBException(ex); } finally { cleanUp(conn, ps, rs); } } 我发现你这里写的有点奇怪,在doLoad()方法里和ejbFindByPrimaryKey方法里用的PK类型不一样。在doLoad方法里你将PK造型为String,难道你的PersonPK和String一样?呵呵,请检查。 不是啊,personId是string类型的,我是将pk转换成string啊 但是Find方法里的PersonPK又是什么意思? PersonPK是主键啊,ejbload里面用取得主键,但是查询得根据personId查啊大哥,有QQ吗,加我吧,好几天了都没解决问题啊,我的QQ24964956 我在ejbload里面加了一句打印personId的语句,发现并没有打印personId,按书上的,我觉得findbyprimary后就会返回一个主键到容器,容器会调用ejbload,看来好像并没调用ejbload似的 公司里在上班的时候不能上QQ,只有MSN:[email protected]我的意思是你既然PersonPK是主键,那personId = (String)entityContext.getPrimaryKey();是不是该成为personId = (PersonPK)entityContext.getPrimaryKey(); 我在ejbload里面加了一句打印personId的语句,发现并没有打印personId,按书上的,我觉得findbyprimary后就会返回一个主键到容器,容器会调用ejbload,看来好像并没调用ejbload似的 又用PersonPK newpk = (PersonPK)entityContext.getPrimaryKey(); personId = newpk.personId;试了也不好用,怪了,不是jboss的问题吧 这个调用过程不会马上发的的,只有在你引入了那个找到的EJB时它才会发生。比如你找到那那个EJB,然后调用了那个EJB的一些方法来获取属性时,它就会调用了。 如何在开发过程中,减少和降低bug的出现 SSH关于异常的处理 关于struts文件下载word文档乱码问题。 struts2 校验框架的问题 数据导入 Dao层需要抽象出来吗? 关于 <html:errors/> 无法显示错误信息 一个很十万火急得问题!!!!!!!!!!!恳求高人指点啊! 出来炸到,请前辈们指教一下 jdk中是否已有JDBC-ODBC Bridge driver了? struts应用的一点理解,不知道对不对,大家看看。 请问哪里能够找到j2eetutorial中文版(本版提供的下载)中的例子程序?谢谢!
public void ejbLoad() {
/**@todo Complete this method*/
personId = (String)entityContext.getPrimaryKey();
System.out.println(personId);
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
try {
conn = getConnection();
ps = conn.prepareStatement(
"SELECT name, phone, email FROM person WHERE personId = ?");
ps.setString(1, personId);
rs = ps.executeQuery();
if (!rs.next())
throw new NoSuchEntityException();
name = rs.getString(1);
phone = rs.getString(2);
email = rs.getString(3);
// set the modified flag to false after loading the data
isModified = false;
} catch (SQLException ex) {
throw new EJBException(ex);
} finally {
cleanUp(conn, ps, rs);
} }
-------------------ejbfindbyprimary---------
public PersonPK ejbFindByPrimaryKey(PersonPK pk) throws FinderException {
/**@todo Complete this method*/
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
try {
conn = getConnection();
ps = conn.prepareStatement(
"SELECT 1 FROM person WHERE personId = ?");
ps.setString(1, pk.personId);
rs = ps.executeQuery(); if (rs.next()) {
System.out.println("return pk");
return pk;
} else {
throw new ObjectNotFoundException();
}
} catch (SQLException ex) {
throw new EJBException(ex);
} finally {
cleanUp(conn, ps, rs);
} }
大哥,有QQ吗,加我吧,好几天了都没解决问题啊,
我的QQ24964956
我的意思是你既然PersonPK是主键,那personId = (String)entityContext.getPrimaryKey();是不是该成为personId = (PersonPK)entityContext.getPrimaryKey();
personId = newpk.personId;
试了也不好用,怪了,不是jboss的问题吧