对不起,搞错了,插入可以,查询显示出错。
// This is the variable we will store all records in.
Collection recs = null;if (error == null) {
try {
recs = home.findAll();
} catch (Exception e) {
exception = e;
error = "Caught \"" + exception.getClass().getName() + "\" while " +
"attempting to find all TemplateBean entries.";
errorStream.println(error);
exception.printStackTrace(errorStream);
}}
<%
Iterator iterator = recs.iterator();
while(iterator.hasNext()) {
Template rec =
(Template) PortableRemoteObject.narrow(iterator.next(),
Template.class);
Integer col_1 = rec.getCol_1();
String col_2 = rec.getCol_2();
Float col_3 = rec.getCol_3(); // put all pk columns in hashtable for URLEncoding
Hashtable cols = new Hashtable();
cols.put("COL_1", col_1.toString()); // URLEncode columns as params to JSP
StringBuffer buf = new StringBuffer();
Enumeration params = cols.keys();
while (params.hasMoreElements()) {
String param = (String)params.nextElement();
String value = (String)cols.get(param);
buf.append(URLEncoder.encode(param) +
"=" + URLEncoder.encode(value));
if (params.hasMoreElements())
buf.append("&");
} String editURL = "edit.jsp?" + buf;
String deleteURL = "delete.jsp?" + buf;
%><TR>
<TD><%= col_1 %></TD>
<TD><%= col_2 %></TD>
<TD><%= col_3 %></TD>
<TD><A href="<%= editURL %>">Edit</A> <A href="<%= deleteURL %>">Delete</A></TD>
</TR><%
} /* for */
%>出错信息:
Caught "com.evermind.server.rmi.OrionRemoteException" while attempting to find all TemplateBean entries.com.evermind.server.rmi.OrionRemoteException: Transaction was rolled back: Error preparing bean instance: com.evermind.transaction.MarshallingXAException; nested exception is: com.evermind.transaction.MarshallingXAException
// This is the variable we will store all records in.
Collection recs = null;if (error == null) {
try {
recs = home.findAll();
} catch (Exception e) {
exception = e;
error = "Caught \"" + exception.getClass().getName() + "\" while " +
"attempting to find all TemplateBean entries.";
errorStream.println(error);
exception.printStackTrace(errorStream);
}}
<%
Iterator iterator = recs.iterator();
while(iterator.hasNext()) {
Template rec =
(Template) PortableRemoteObject.narrow(iterator.next(),
Template.class);
Integer col_1 = rec.getCol_1();
String col_2 = rec.getCol_2();
Float col_3 = rec.getCol_3(); // put all pk columns in hashtable for URLEncoding
Hashtable cols = new Hashtable();
cols.put("COL_1", col_1.toString()); // URLEncode columns as params to JSP
StringBuffer buf = new StringBuffer();
Enumeration params = cols.keys();
while (params.hasMoreElements()) {
String param = (String)params.nextElement();
String value = (String)cols.get(param);
buf.append(URLEncoder.encode(param) +
"=" + URLEncoder.encode(value));
if (params.hasMoreElements())
buf.append("&");
} String editURL = "edit.jsp?" + buf;
String deleteURL = "delete.jsp?" + buf;
%><TR>
<TD><%= col_1 %></TD>
<TD><%= col_2 %></TD>
<TD><%= col_3 %></TD>
<TD><A href="<%= editURL %>">Edit</A> <A href="<%= deleteURL %>">Delete</A></TD>
</TR><%
} /* for */
%>出错信息:
Caught "com.evermind.server.rmi.OrionRemoteException" while attempting to find all TemplateBean entries.com.evermind.server.rmi.OrionRemoteException: Transaction was rolled back: Error preparing bean instance: com.evermind.transaction.MarshallingXAException; nested exception is: com.evermind.transaction.MarshallingXAException
public Collection ejbFindAll() throws FinderException, RemoteException
{
System.out.println("TemplateBean.ejbFindAll(): begin");
Vector recs = new Vector();
try {
conn = getConnection(dsName);
ps = conn.prepareStatement(findAllStatement);
ps.executeQuery();
ResultSet rs = ps.getResultSet();
int i = 0;
while (rs.next()) {
pk = new TemplatePK();
pk.col_1 = new Integer(rs.getInt(1));
pk.col_2 = new String(rs.getString(2));
pk.col_3 = new Float(rs.getFloat(3));
recs.add(pk);
}
} catch (SQLException e) {
throw new FinderException(e.getMessage());
} finally {
try {
ps.close();
} catch (Exception e) {}
try {
conn.close();
} catch (Exception e) {}
}
return recs;
}
还有啊,最好用cmp
public void setCol_1(Integer Col_1)
{
this.Col_1 = Col_1;
}public void setCol_2(String Col_2)
{
this.Col_2 = Col_2;
}public void setCol_3(Float Col_3)
{
this.Col_3 = Col_3;
}public void getAll()
{
if(Col_1 != null) {
sql = "select * from templatebean where Col_1=" + Col_1 + " and ";
}
......
}