3 Replies Latest reply on Nov 6, 2002 7:09 PM by Stephen Coy

    JBoss stores java.lang.String incorrectly ... help please...

    Tejas Newbie

      Hi,
      Posting this question again to see if it catches the attention of JBoss Gurus.
      My code is giving strange results on Jboss (JBoss running on Windows NT). The code is in an OJB and runs on JBoss.

      Some of the relevant code fragment is as under :

      arr = (ARRAY)rset.getArray(1);
      Object [] obj = (Object []) arr.getArray();

      String strColName = null;
      String strTableName = null;
      String strColVal = null;

      Logger.write("SQL Query fetched records, starting to process records" , true);

      for(int q = 0; q < obj.length; q++ )
      {
      HashMap hashMap = new HashMap();

      STRUCT strc = (STRUCT) obj[q];
      Object [] obj1 = (Object []) strc.getAttributes();
      //Add instance data to the HashMap
      for (int colCount=0; colCount < columnNames.length ; colCount++)
      {
      strColName = (String) columnNames[colCount];
      if(obj1[colCount] != null && obj1[colCount] instanceof java.lang.String )
      {
      strColVal = (String) obj1[colCount];
      System.out.println("The column value is " + strColVal);
      hashMap.put(strColName ,
      new Attribute(strColVal.toString() ,"") );
      }
      else
      {
      hashMap.put(strColName ,
      new Attribute(obj1[colCount],"") );
      }


      The above code is not complete, but gives only the relevant section that is experiencing problems.
      The above code does a very simple task, fetches data from the database, and puts the each of the data row in the hashmap. Oracle ARRAY mechanism is used to fetch the data.

      Please take a look at the System.out code line. It is inside if block. Now, the strange thing is that when the System.out line is executed by JBoss, the column value is printed as "0x53544D2D31204C2D312E31206F74"

      How is this possible ? Is something wrong in my code ??
      The fact that System.out code is executed, means that the data is of java.lang.String, why does Jboss print the hex representation of the string ????

      Now, when I run the same code on OC4J, the results are as expected, OC4J prints the string as expected.

      Has anyone faced this problem before ??? Can someone give some help ?
      I would really like my project to use JBoss, but if this cannot be solved, I guess I'll have to move on to OC4J as time scales are very thin.

      Can someone please help....

      Thanks,
      Tejas

        • 1. Re: JBoss stores java.lang.String incorrectly ... help pleas
          Stephen Coy Novice

          I think you are not getting any replies because:

          1) OJB is ambiguous at best - Oracle Java Bean or jakarta apache OJB?

          2) You have code that shows how you are extracting your data, but not how you are storing it. How are you storing it? What are you using for database mappings?

          For what it's worth, there is some chance that JBoss 3.0.4 will handle this better.

          Steve

          • 2. Re: JBoss stores java.lang.String incorrectly ... help pleas
            Tejas Newbie

            Hi,

            Thanks for replying and your interest.

            By OJB, I mean Ordinary Java Bean, hope that clarifies.

            I was using JBoss version 3.0.3, but as per your advise I tried the solution with Jboss ver 3.0.4 running on Windows NT, but still the same results as earlier.

            I am using Oracle 8i database. I have created a table and a Oracle Type similar to this table.

            The sql query I used is,
            select cast ( multiset ( SELECT cola, colb from tablea ) as MyTypeMaxList ) from dual

            In the oracle database, the structures created are,
            create or replace type MyTypeMax_T AS OBJECT (
            cola varchar2(50),
            colb varchar2(50)
            );
            /
            create or replace type MyTypeMaxList AS table of MyTypeMax_T;
            /

            On java side I use,
            ArrayDescriptor descr = ArrayDescriptor.createDescriptor(arraydesciptorname, dbConnection);
            stmt = (OraclePreparedStatement)dbConnection.prepareStatement(sqlString);
            stmt.setLong(1, (new Long("1").parseLong(sqlWhere)));
            arr = new ARRAY(descr, dbConnection, null);

            rset = (OracleResultSet)stmt.executeQuery();
            Logger.write("SQL Query executed" , true);
            rset.next();

            arr = (ARRAY)rset.getArray(1);
            Object [] obj = (Object []) arr.getArray();

            Hope this makes it all clear now along with my earlier email.

            What makes me wonder is the fact that the same code runs fine on OC4J server running on WindowsNT.

            Please do give more ideas and pointers....

            Many Thanks,
            Tejas

            • 3. Re: JBoss stores java.lang.String incorrectly ... help pleas
              Stephen Coy Novice

              Your code does not appear to be interacting with JBoss at all that I can see.

              I suspect that different Oracle JDBC drivers are being used when you swap between the JBoss platform and the OC4J server.