jsp中如何通过accessbean从DB中获取数据

发布于 2024-12-27 12:23:24 字数 1721 浏览 2 评论 0原文

添加到数据库(提交数据)后,在我的AccessBean中没有获取最新插入的数据。但是当我再次回到jsp时,数据就可用了。我不知道如何解决这个问题。

下面是提交数据后在cmdImpl中插入的代码

AddressAccessBean add  = new AddressAccessBean(Long.parseLong(memberid),shipid);
                    shipBean.setInitKey_ShipToCodeName(shipid);

   add.setAddressField2(shipBean.getName()+shipBean.getCity()+shipBean.getState());                  
   add.setAddressField1("WD");

   add.setMemberId(memberid);

   add.setAddressField3(shipid);

   add.setStatus("P");

   add.commitCopyHelper();

。尝试通过accessbeans及其finder方法在jsp上获取数据并显示到jsp中的表中

<%
String[] member_Id = (String[])request.getAttribute("memberid");                        
String memberId=member_Id[0];
AddressAccessBean add = new AddressAccessBean();
java.util.Enumeration enu = add.findByMemberId(Long.parseLong(memberId));
while (enu.hasMoreElements()) {
      AddressAccessBean as = (AddressAccessBean) enu.nextElement();
      if (as.getAddressField3() != null && as.getAddressField1().equals("WD")) {
            com.ibm.commerce.extension.objects.xShipToCodeAccessBean bb = new com.ibm.commerce.extension.objects.xShipToCodeAccessBean().findByShipToCodeName(as.getAddressField3());
                                %>
<TR>
<Td ALIGN="LEFT" width="20%"><%=as.getAddressField2()%></Td>
<Td ALIGN="LEFT" width="20%"><%=bb.getName()%></Td>
<Td ALIGN="LEFT" size="15%"><%=bb.getShipToCodeName()%></Td>
<Td ALIGN="LEFT" size="10%"><%=bb.getCity()%></Td>
<Td ALIGN="LEFT" size="10%"><%=bb.getState()%></Td>
<Td ALIGN="LEFT" size="10%"><%=bb.getSoldTo()%>
</Td>

After adding the to the db (commiting the data), not getting the latest inserted data in my AccessBean. But when I come backto the jsp again the data is available. I don't know how to resolve the issue.

Below is the insert code in cmdImpl

AddressAccessBean add  = new AddressAccessBean(Long.parseLong(memberid),shipid);
                    shipBean.setInitKey_ShipToCodeName(shipid);

   add.setAddressField2(shipBean.getName()+shipBean.getCity()+shipBean.getState());                  
   add.setAddressField1("WD");

   add.setMemberId(memberid);

   add.setAddressField3(shipid);

   add.setStatus("P");

   add.commitCopyHelper();

After commiting the data.trying to fetch data on jsp through accessbeans and their finder methods and displaying into table in jsp

<%
String[] member_Id = (String[])request.getAttribute("memberid");                        
String memberId=member_Id[0];
AddressAccessBean add = new AddressAccessBean();
java.util.Enumeration enu = add.findByMemberId(Long.parseLong(memberId));
while (enu.hasMoreElements()) {
      AddressAccessBean as = (AddressAccessBean) enu.nextElement();
      if (as.getAddressField3() != null && as.getAddressField1().equals("WD")) {
            com.ibm.commerce.extension.objects.xShipToCodeAccessBean bb = new com.ibm.commerce.extension.objects.xShipToCodeAccessBean().findByShipToCodeName(as.getAddressField3());
                                %>
<TR>
<Td ALIGN="LEFT" width="20%"><%=as.getAddressField2()%></Td>
<Td ALIGN="LEFT" width="20%"><%=bb.getName()%></Td>
<Td ALIGN="LEFT" size="15%"><%=bb.getShipToCodeName()%></Td>
<Td ALIGN="LEFT" size="10%"><%=bb.getCity()%></Td>
<Td ALIGN="LEFT" size="10%"><%=bb.getState()%></Td>
<Td ALIGN="LEFT" size="10%"><%=bb.getSoldTo()%>
</Td>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

缱绻入梦 2025-01-03 12:23:24

如果您转发到 JSP,则通过实体/访问 bean 插入的数据对于查找器查询将不可见。即,如果您转发到 JSP 而不是重定向,则事务仅在执行 JSP 后才会提交。提交事务后,实体 bean 更改将写入数据库。这就是为什么您在尝试使用查找器查询时无法看到插入的原因。

您有两个选择:-

  1. 将转发 JSP 转换为重定向 JSP。
  2. 使用AddressAccessBean的setInitKey方法使用地址id来获取数据

If you are fowarding to the JSP, data inserted through entity/access beans will not be visible to a finder query. i.e., if you are forwarding to a JSP instead of a redirect, transaction gets committed only after the execution of JSP. Entity bean changes are written to db after transaction is committed. Thats is why you are not able to see the insert while trying to use a finder query.

You have two options :-

  1. Convert forward JSP to a redirect JSP.
  2. Use setInitKey method of the AddressAccessBean using the address id to fetch data
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文