EJB method returns 2D String array

Hi,
one of EJB method returns a 2 dimensional array of String. Is it okay? Is this a good EJB programming practice?
Thanks
Sabir

Its ok. but not consdered as best practice now.
Check out the DTO pattern(previously called value obects from sun's site.
--Ashwani                                                                                                                                                                                                                                                                       

Similar Messages

  • Error returning large String arrays from web service

    Hi,
    I currently have an EJB that returns a String[] array that I have implemented as
    a Web Service. When I execute a Java client (JSP) from Weblogic, I don't have a problem
    as long as the returned array is relatively small, but when the array starts to get
    a little larger (say 20 elements, about 30 chars each), I consistently get:
    SAXException: java.lang.IllegalArgumentException:array element type mismatch.
    Strangely enough, when my web service client is a .asp page running under MS IIS
    (using the MS SOAP Toolkit), it works fine. I have returned as many as 15000 - 20000
    array elements in one call. And since I am calling the same Weblogic EJB with the
    MS client, I know it's a problem with the Java client, not the EJB.
    Anybody know of a bug or had this experience before? Or know what I might be doing
    wrong? FYI, I am using Weblogic 6.1 SP2.
    Thanks,
    Steve

    Hi Steve,
    Sure we're interested...I'll pass this along to the XML folks.
    Thanks for the feedback,
    Bruce
    Steve Alexander wrote:
    In case anyone is interested, I solved my problem. I was mis-diagnosing the problem
    - thinking it was a size issue when it actually was a data issue. On the calls where
    I was returning a large array, some of the array members were null. When I made them
    enpty strings "", it worked. Apparently the default SAX parser BEA uses doesn't like
    the nulls, whereas the MS parser doesn't care.
    "Steve Alexander" <[email protected]> wrote:
    Thanks Bruce,
    FYI - I have reproduced the problem on WL7.0. I have turned it in to support
    as you
    suggested.
    Steve
    Bruce Stephens <[email protected]> wrote:
    Hi Steve,
    This does not ring any bells, however I would suggest that you file a support
    case. If it
    is an option you might try a later release (7.0).
    Bruce
    Steve Alexander wrote:
    Hi,
    I currently have an EJB that returns a String[] array that I have implementedas
    a Web Service. When I execute a Java client (JSP) from Weblogic, I don'thave a problem
    as long as the returned array is relatively small, but when the arraystarts to get
    a little larger (say 20 elements, about 30 chars each), I consistentlyget:
    SAXException: java.lang.IllegalArgumentException:array element type mismatch.
    Strangely enough, when my web service client is a .asp page running underMS IIS
    (using the MS SOAP Toolkit), it works fine. I have returned as many as15000 - 20000
    array elements in one call. And since I am calling the same Weblogic
    EJB
    with the
    MS client, I know it's a problem with the Java client, not the EJB.
    Anybody know of a bug or had this experience before? Or know what I mightbe doing
    wrong? FYI, I am using Weblogic 6.1 SP2.
    Thanks,
    Steve

  • Can an EJB method return processing results to its calling program?

    Hi there,
    I have an EJB method which does JDBC connection to a UDB. I want the ResultSet to be returned to JSP so I can format them in the page itself. I got an ClassCastException at the return statement. Could anybody point out what I might be missing?
    Thanks a lot.
    Andy

    Here is the code related:
              try
                   Context jndi = AuditPublicService.getContext();
                   Object obj = jndi.lookup(AuditInterface.ALIAS);
                   AuditHome auditHome =
                        (AuditHome) PortableRemoteObject.narrow(obj, AuditHome.class);
                   Audit audit = auditHome.create();
                        this.rs = (ResultSet) audit.read();
              catch (Throwable t)
                   System.out.println("Test.read():failed." + t.toString());
                   t.printStackTrace();
    and this is what I got:
    Test.read():failed.java.lang.ClassCastException
    java.lang.ClassCastException
    P.S. When I track down to the return statement(return rs) in the audit.read(), I can see that the rs is exactly what I want, but failed when the EJB stub tries to cast it to Serializable. I tried to implements java.io.Serializable in both the calling class and the EJB. it didn't work.

  • Can EJB method return another EJB?

    Hello,
    I am new to EJB technology. I am working with Sun Application Server bundled in Netbeans 4.1
    Is it po[b]ssible a method of a session bean to return another EJB which is instantiated with arguments depended on the method?
    If no, is there an alternative way?
    thank you in advance, Kostas

    Is it possible within the SessionBean method to
    call another Session Bean, create it using the
    local interface, pass some parameters using setter
    methods, then cast it from local interface to
    remote and send it to the user?I think it's not possible casing Local Interface into Remote Intrface, because they inherit from different classes.
    Remote interface extends EJBObject and Local interface extends EJBLocalObject
    Fil

  • Bug? EJB method Return Value and Client Catch the Exception?

    oc4j 9.0.3 on the windows 2000
    I write a Stateless Session Bean named SB1 ,
    and define application exception.
    The Code as follow:
    public class AppErrorException extends Exception
    public interface SB1 extends EJBObject
    public String getMemono(String sysID, String rptKind, String parentMemono)
    throws RemoteException, AppErrorException;
    public class SB1Bean implements SessionBean
    public String getMemono(String sysID, String rptKind, String parentMemono)
    throws RemoteException, AppErrorException
    throw new AppErrorException("Error in getMemono");
    public class SB1TestClient
    try
    memomo= sb1.getMemono(.....);
    catch(AppErrorException ae)
    ae.printStackTrace();
    I found a bug.
    If SB1.getMemono() throws the AppErrorException, but SB1TestClient will not catch any Exception.
    It is not normal!!!!
    [cf]
    But If I convert "public String getMemono(...)" into "public void getMemono(...)",
    When SB1.getMemono() throws the AppErrorException, but SB1TestClient will catch any Exception.
    It is normal.

    getMemono(.......)'s code as follow:
    public String getMemono(String sysID, String rptKind, String parentMemono)
    throws AppErrorException
    log("getMemono("+sysID+", "+rptKind+", "+parentMemono+")");
    Connection connection= null;
    CallableStatement statement = null;
    String memono= "";
    short retCode= -1;
    String retMsg= "";
    try
    String sql= this.CALL_SPGETMEMONO;
    connection = ResourceAssistant.getDBConnectionLocal("awmsDS");
    statement= connection.prepareCall(sql);
    statement.setString(1, sysID.trim());
    statement.setString(2, rptKind.trim());
    statement.setString(3, parentMemono.trim());
    statement.registerOutParameter(4, java.sql.Types.VARCHAR);
    statement.registerOutParameter(5, java.sql.Types.SMALLINT);
    statement.registerOutParameter(6, java.sql.Types.VARCHAR);
    statement.executeQuery();
    retCode= statement.getShort(5);
    retMsg= statement.getString(6);
    log("retCode="+retCode);
    log("retMsg="+retMsg);
    if (retCode==AppConfig.SHORT_SP_RETCODE_FAILED)
    log("retCode==AppConfig.SHORT_SP_RETCODE_FAILED");
    this.sessionContext.setRollbackOnly();
    throw new AppErrorException(retMsg);
    memono= statement.getString(4);
    log("memono="+memono);
    if (rptKind.trim().length()<6)
    log("rptKind.trim().length()<6");
    this.sessionContext.setRollbackOnly();
    throw new AppErrorException("rptKind.trim().length()<6");
    memono= "SS";
    catch (AppErrorException ae)
    log("catch(AppErrorException ae)");
    throw ae;
    //throw new EJBException(ae.getErrMsg());
    catch (Exception e)
    log("catch (Exception e)");
    this.sessionContext.setRollbackOnly();
    throw new AppErrorException(IExceptionConst.ERR_MSG_SYSMEMONO_00000, e.toString());
    //throw new EJBException(IExceptionConst.ERR_MSG_SYSMEMONO_00000+", "+e.toString());
    finally
    log("this.sessionContext.getRollbackOnly()="+this.sessionContext.getRollbackOnly());
    ResourceAssistant.cleanup(connection,statement);
    return memono;

  • Methods returning String

    Do Methods returning String create a String object in memeory and pass back the reference to the calling Method?
    Thanks

    hmm, i'll take a shot at answering your query - hope this meets your requirement ... Java does manipulate objects by reference, and all object variables are references. So when a method returns a String object (this object would be created within the scope of the method) the object reference is returned to the caller.
    Now the point of confusion usually happens since, Java doesn't pass method arguments by reference; it passes them by value. Java passes object references by value as well. What this means is the references passed to the method are actually copies of the original references.Java copies and passes the reference by value, not the object. Thus, method manipulations on the object reference will alter the objects, since the references point to the original objects. But since the references are copies, swaps will fail.
    Hope the above helps.
    John Morrison

  • String Array to Comma spearated list

    Hey Guys,
    I have a struts application that receives a string[] array of product numbers corresponding to those that a user has selected. I need to put these into a SQL query in the form of "PRODUCTS.PRODUCT_NAME IN ('product1','product2','product3')" -- in otherwords, a comma separated list, with each item wrapped in apostrophes.
    I can successfully drop in individual items using notation like the following:
    <c:set var="where" value="and PRODUCTS.PRODUCT_NAME IN ('${formChecker4.selectedProductListForm2[0]}')" />What I'm not sure about is the best way to create my comma separated list. In my formChecker4 class, I have getSelectedProductListForm2() and setSelectedProductListForm2() methods, but these expect and return a string[] array, not a plain string. Does anyone have any handy suggestions for converting my array into a string, either within my class or within my EL tags?
    Here's some of my formChecker4 class:
        private String[] selectedProductListForm2;
        public String[] getSelectedProductListForm2() {
            return this.selectedProductListForm2;
        public void setSelectedProductListForm2(String[] selectedProductListForm2) {
            if (selectedProductListForm2.length == 0) {
                this.selectedProductListForm2 = null;
            } else {
                this.selectedProductListForm2 = selectedProductListForm2;
        }

    1) don't do it in JSP
    2) [Use a prepared statement. |http://java.sun.com/docs/books/tutorial/jdbc/basics/prepared.html]

  • Converting String Array -- String

    Hi All,
    I am converting String array to string using the following code:
    String[] a= ....;
    StringBuffer result = new StringBuffer();
    if (a.length > 0) {
    result.append(a[0]);
    for (int i=1; i<a.length; i++) {
    result.append(a);
    return result.toString();
    Is there is any other easy or efficient way to convert rather than the above code ?
    Thanks,
    J.Kathir

    It could have been written:
    StringBuffer result = new StringBuffer();
    for(int i=0; i<a.length; ++ i)
        result.append(a);
    return result.toString();
    Or in 1.5 lingo
    StringBuilder result = new StringBuilder(); //slightly less overhead
    for(String s : a)
        result.append(s);
    return result.toString();If you aren't picky about the format of the resulting string,
    you could use the java.utilArrays method )]toString(Object[]):
    String[] array= {"Hello", "World", "this", "is", "a", "1.5", "method"};
    String s = Arrays.toString(array); //[Hello, World, this, is, a, 1.5, method]

  • Calling a method that returns an object Array

    Hello.
    During a JNICALL , I wish to call a method which returns an object array.
    ie my java class has a method of the form
    public MyObject[] getSomeObjects(String aString){
    MyObject[] theObjects=new MyObject[10];
    return theObjects
    Is there an equivalent to (env)->CallObjectMethod(...
    which returns a jobjectArray instead of a jobject, and if not could somebody suggest a way around this.
    Thanks,
    Neil

    I believe an array oj jobjects is also a jobject. You can then cast it to another class.

  • WebService problem: only the first element of a string array is returned

    Hello,
    i did the J2EE QuickCarRental tutorial and extended it by some features: I created another entity bean and implemented four new methods in the QuickOrderProcessor. Then i deployed it as a WebService and accessed it using the Visual Composer.
    Everything works fine except the return value of one WebService method. I created a method with the return value String[]. But the Visual Composer reads it as String. Only the first element of the resulting string array is displayed. Although the test at the web-page http://<server>:<port>/QuickCarRentalService/Config1 displays the whole string array with all its elements. What did i wrong?
    Another problem is that after deploying the J2EE-Application with new WebService methods the changes are not visible inside the visual composer. Although the test at the web-page http://<server>:<port>/QuickCarRentalService/Config1 displays the changes. Do i have to restart the WebService system in the portal content? If yes how can i do that?

    Here are details about setting up and using web services and some examples:
    /people/prakash.darji/blog/2006/10/10/external-web-service-proxy-configuration-for-visual-composer

  • Returning String Array

    I'm trying to create a function (method?) for parsing some log files. The first index of the string array I want returned will contain a 'key' on what I'm doing with the log files (since they'll be formatted in several different ways depending on what's happening) and the rest will just return tokens from the logs. Here's what I have so far:
        public static String[] parseLog(String inString){
            StringTokenizer st = new StringTokenizer(inString, "\"<>");
            int stNum = st.countTokens();
            String[] parsedOut = new String[stNum + 1];
            if (inString.contains("disconnected")) {
                parsedOut[0] = "read";
            for (int x = 1; st.hasMoreTokens() ; x++){
                parsedOut[x] = st.nextToken().trim();
            return parsedOut;
        public static void main(String[] args) {
            String line = "????log L 08/15/2008 - 20:28:37: \"underTHEinfluence johnRAMBO<16><STEAM_0:0:204495><>\" disconnected";
            System.out.println("Parsed: " + parseLog(line));
        }{code}
    It compiles with no errors, but I'm getting this: Parsed: [Ljava.lang.String;@e09713
    Edited by: mr0ldie on Aug 16, 2008 1:37 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    prometheuzz wrote:
    A String representation of the array is given, while you want to display the individual items from the array.
    Try this:
    System.out.println(java.util.Arrays.toString(yourArray));
    Need closures - want to do mapchar(yourarray, System.out.println);
    :)

  • Find(String pkey) method returns multiple object of the same row

    I'm not quite sure what i've done or havent done, but I've implemented updating a row using the em.persist(Object) method.....works great, but after i did that a few times the find(String pkey) method returns multiple copies of 1 row in the db
    here are two rows in the db
    personid(PK) firstName lastName
    1234 joe jones
    2345 rachel jones
    when i execute any query looking for people with the last name jones, ie
    select object(p) from Person p where p.lastName='jones'
    it returns multiple objects of each row ie
    1234 joe jones
    1234 joe jones
    1234 joe jones
    1234 joe jones
    2345 rachel jones
    2345 rachel jones
    2345 rachel jones
    2345 rachel jones
    There is only one row for both rachel and joe in the db, but why is the entity manager returning multiple objects of each, and how do i prevent that without using DISTINCT?
    Thanks for the help in advance

    Sorry, i forgot to mention i'm using ejb 3 and jboss

  • Return String array in server side

    i wrote a bean which contains a function return String array (
    String[] ). It shows no error on compile time, and also in
    generate jar file. However, when i generate it to an ear file,
    the syntax of the wsdl file is not correct so the client can't
    call this function becuase the xml can't parse the wsdl.
    When i change the return type to String, everything is ok. Does
    anybody know what's happen? I really have no idea on it, thx.

    This is why I wanted to see some code. I wanted to see how you are trying to move the array from one class to another.
    This should work... provided that the array is initialised correctly in ClassA. If you are doing it like this, please post some code and I'll help you fix it.
    class ClassA{
    public String[] getMyArray(){
    return myArray;
    class ClassB{
    public void myMethod(){
    ClassA myA = new ClassA();
    String[] newArray = myA.getMyArray();
    }

  • Returning more than one value/object from an EJB method

    Hi,
    I have the follong method in the remote interface of my EJB:
    void createSomeObject( MyObject obj1, List returnList1, Map returnMap1);
    Since i want to return a List (returnList1) and a Map(returnMap1) from my EJB method "createSomeObjects", i am passing these as parameters thinking they will be passed by reference and the client(servlet) gets the changes the EJB made to these objects.
    But it doesn't seem to be working, the EJB is filling the List and Map objects and the servlet doesn't get it (pass by value problem).
    My understading is that, all parameters to an EJBs are passed by value(because they are remote calls, the RMI thing), let me know if this right.
    Is there any workaround apart from the following alternative?
    Alternatives:
    1. Wrap "List list1" and "Map map1" in another model and return this instead of passing them as parameters.
    Thanks
    Vasu

    My understading is that, all parameters to an EJBs
    are passed by value(because they are remote calls,
    the RMI thing), let me know if this right.Yes, that is correct - which you should know from your introduction to J2EE reading.
    Is there any workaround apart from the following
    alternative?
    Alternatives:
    1. Wrap "List list1" and "Map map1" in another model
    and return this instead of passing them as
    parameters.No.

  • How Do I Call PL/SQL Stored Procedure That Returns String Array??

    I Have Problem Calling An Oracle(8i) Stored Procedure That Returns Array Type (Multi Rows)
    (As Good As String Array Type..)
    In This Fourm, I Can't Find Out Example Source.
    (Question is Exist.. But No Answer..)
    I Want An Example,, Because I'm A Beginner...
    (I Wonder...)
    If It Is Impossible, Please Told Me.. "Impossible"
    Then, I'll Give Up to Resolve This Way.....
    Please Help Me !!!
    Thanks in advance,

    // Try the following, I appologize that I have not compiled and run this ... but it is headed in the right direction
    import java.sql.*;
    class RunStoredProc
    public static void main(String args[])
    throws SQLException
    try
    Class.forName("oracle.jdbc.driver.OracleDriver");
    catch(Exception ex)
    ex.printStackTrace();
    java.util.Properties props = new java.util.Properties();
    props.put("user", "********"); // you need to replace stars with db userid
    props.put("password", "********"); // you need to replace stars with userid db password
              // below replace machine.domain.com and DBNAME, and port address if different than 1521
    Connection conn =
    DriverManager.getConnection("jdbc:oracle:thin:@machine.domain.com:1521:DBNAME", props);
    // replace "Your Stored Procedure" with your stored procedure
    CallableStatement stmt = conn.prepareCall("Your Stored Procedure");
    ResultSet rset = stmt.execute();
    while(rset.next())
    System.out.println(rset.getString(1));

Maybe you are looking for

  • IPhone 3GS with OS4 upgrade - using Apple's Bluetooth Keyboard

    Help! I just upgraded my iPhone 3GS to OS 4. I also bought an Apple Bluetooth Keyboard. It's awesome except for one thing. After I type a text message and go to send it, I push the "Send/Enter" button and it just goes to the next line, it won't actua

  • How to Release jstring (C++ dll calls Java)

    I'm trying to call a method from a Dll (written in C++) to Java. Pseudo might look like this String cstr = "abcdefghijklmnopqrstuvwxyz"; jstring jstr = NewStringUTF(cstr); CallJavaMethod(classid, methodid, jstr); // so problem is how to release this

  • VPN disconnects my internet

    Hi wondering if anyone can help me please. For the past 3 months ever since I upgraded to Snow Leopard, my university's VPN connection has not worked on my Mac. What happens is that, when I click the vpn to connect, it appears to establish a connecti

  • Recovery installation fails

    Hi, I have Toshiba Satellite Laptop Windows Vista, It was hanging so I tried to recoverr to factory settings, after taking my backup. The first disk i get the meesage "Cannot read from source file or disk " Boot.wim type WIM file I have option to ski

  • AE  is connected but no audio output??

    I use my AE to send audio output from iTunes to my stereo system and it was working fine until just recently. The Airport Utility shows that my iMac sees my AE, and the green line is shining on the AE, but there is no sound coming out of the stereo (