javax.ejb.EJBException: ejbCreate: 将截断字符串或二进制数据。非常像是字符串超长。如firstName、lastName等超过数据库设计的字段长度。

解决方案 »

  1.   

    字符串超长?以下是我不通过ejb向数据库插入数据的客户端,那怎么不会出错?
    import java.sql.*;
    import javax.sql.*;
    import javax.naming.*;
    import java.math.*;
    import java.util.*;public class Client2
    { public static void main(String[] args)
    {
    try
    {
    String url="t3://localhost:7001";
    Properties h = new Properties();

    h.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
    h.put(Context.PROVIDER_URL, url);
    Context ctx=new InitialContext(h);

                DataSource ds = (DataSource) ctx.lookup("SavingsAccountDB");
    Connection con =  ds.getConnection();String insertStatement ="insert into savingsaccount values ( ? , ? , ? , ? )";
    PreparedStatement prepStmt =con.prepareStatement(insertStatement);
    prepStmt.setString(1, "11");
    prepStmt.setString(2, "sdfsdf");
    prepStmt.setString(3, "sdfsdfs");
    prepStmt.setBigDecimal(4, new BigDecimal(100));
    prepStmt.executeUpdate();
    prepStmt.close();

    }
    catch(Exception e)
    {
    System.out.println("error");
    }

        
    }
    }
      

  2.   

    把错误多贴出来一些看看,没有抛你自己的Exception吗?
      

  3.   

    这是所有异常信息:
    Caught an Exception: EJB Exception:; nested exception is: 
    javax.ejb.EJBException: ejbCreate: 将截断字符串或二进制数据。 Severity 16, State 2, Procedure 'NW05 null', Line 1Start server side stack trace:
    java.rmi.RemoteException: EJB Exception:; nested exception is: 
    javax.ejb.EJBException: ejbCreate: 将截断字符串或二进制数据。 Severity 16, State 2, Procedure 'NW05 null', Line 1
    javax.ejb.EJBException: ejbCreate: 将截断字符串或二进制数据。 Severity 16, State 2, Procedure 'NW05 null', Line 1
    at beantest2.SavingsAccountBean.ejbCreate(SavingsAccountBean.java:115)
    at beantest2.SavingsAccountBean_d8mx44_Impl.ejbCreate(SavingsAccountBean_d8mx44_Impl.java:172)
    at java.lang.reflect.Method.invoke(Native Method)
    at weblogic.ejb20.manager.DBManager.create(DBManager.java:737)
    at weblogic.ejb20.manager.DBManager.remoteCreate(DBManager.java:707)
    at weblogic.ejb20.internal.EntityEJBHome.create(EntityEJBHome.java:250)
    at beantest2.SavingsAccountBean_d8mx44_HomeImpl.create(SavingsAccountBean_d8mx44_HomeImpl.java:80)
    at beantest2.SavingsAccountBean_d8mx44_HomeImpl_WLSkel.invoke(Unknown Source)
    at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:346)
    at weblogic.rmi.cluster.ReplicaAwareServerRef.invoke(ReplicaAwareServerRef.java:114)
    at weblogic.rmi.internal.BasicServerRef$1.run(BasicServerRef.java:300)
    at weblogic.security.service.SecurityServiceManager.runAs(SecurityServiceManager.java:762)
    at weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.java:295)
    at weblogic.rmi.internal.BasicExecuteRequest.execute(BasicExecuteRequest.java:30)
    at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:152)
    at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:133)
    End  server side stack trace以下是ejb的客户端:
    import java.util.*;
    import java.math.*;
    import javax.naming.Context;
    import javax.naming.InitialContext;
    import javax.rmi.PortableRemoteObject;import beantest2.*;public class Client
    {
    public static void main(String [] arg)
    {
    try
    {
    String url="t3://localhost:7001";
    Properties h = new Properties();

    h.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
                h.put(Context.PROVIDER_URL, url);
                Context ctx=new InitialContext(h);

                System.out.println("Getting the EJBHome object…");
    Object objref = ctx.lookup("SavingsAccountHome");
    System.out.println("find ok");
    SavingsAccountHome home = (SavingsAccountHome)PortableRemoteObject.narrow(objref, SavingsAccountHome.class);


       BigDecimal zeroAmount = new BigDecimal("10.00");
       SavingsAccount duke = home.create("12312", "23", "3423", zeroAmount);
       duke.credit(new BigDecimal("88.50"));
       duke.debit(new BigDecimal("20.25"));
       BigDecimal balance = duke.getBalance();
       System.out.println("balance = " + balance);
       duke.remove();   } 
       catch (Exception ex) {
       System.err.println("Caught an Exception: " 
       + ex.getMessage());   } 
     }
    }
      

  4.   

    不知道为什么是java.rmi.RemoteException,我全部用的是本地接口啊