Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Java
  4. array?

array?

Scheduled Pinned Locked Moved Java
javaquestionoracledata-structureshelp
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    benjamin yap
    wrote on last edited by
    #1

    Hi, i got this problem when i retrieve my array

    Result = [org.me.sms.Records@71cb25, org.me.sms.Records@cff49f, org.me.sms.Records@c510e3]

    how do i retrieve the orignator and text of it? This is my web service code

    @WebMethod(operationName = "RetrieveSMS")
    public Records\[\] RetrieveSMS(@WebParam(name = "username") String username, @WebParam(name = "password") String password, @WebParam(name = "keyword") String keyword) {
        //TODO write your implementation code here:
        ArrayList list = new ArrayList();
        ResultSet rs = null;
        String statement=null;
        try {
            Connection conn = null;
    
            Class.forName("oracle.jdbc.driver.OracleDriver");
            conn = DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:xe", "smslib", "smslib");
    
            Statement s = conn.createStatement();
            statement = "Select \* from app\_"+keyword;
            rs = s.executeQuery(statement);
            Records r=null;
            while(rs.next())
            {
                //String text =rs.getString("text");
                //list.add(text);
                r = new Records();
                r.setNumber(rs.getLong("originator"));
                r.setText(rs.getString("text"));
                list.add(r);
            }
            s.close();
            conn.close();
            return (Records\[\])list.toArray(new Records\[list.size()\]);
            //return r;
    
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return null;
    }
    

    and my java file

    public class Records {

    private long number;
    private String text;
    
    public long getNumber()
    {
        return number;
    }
    public void setNumber(long num)
    {
        this.number = num;
    }
    
    public String getText()
    {
        return text;
    }
    public void setText(String text)
    {
        this.text = text;
    }
    

    }

    This is my JSP that call the method

    <%
    try {
    org.me.sms.SMSWebServiceService service = new org.me.sms.SMSWebServiceService();
    org.me.sms.SMSWebService port = service.getSMSWebServicePort();
    java.lang.String username = "";
    java.lang.String password = "";
    java.lang.String keyword = "Temp";

    java.util.List<org.me.sms.Records> result = port.retrieveSMS(username, password, keyword);
    
    
        out.println("Result = "+result);
    
    } catch (Exception ex) {
    
    }
    %>
    
    D 1 Reply Last reply
    0
    • B benjamin yap

      Hi, i got this problem when i retrieve my array

      Result = [org.me.sms.Records@71cb25, org.me.sms.Records@cff49f, org.me.sms.Records@c510e3]

      how do i retrieve the orignator and text of it? This is my web service code

      @WebMethod(operationName = "RetrieveSMS")
      public Records\[\] RetrieveSMS(@WebParam(name = "username") String username, @WebParam(name = "password") String password, @WebParam(name = "keyword") String keyword) {
          //TODO write your implementation code here:
          ArrayList list = new ArrayList();
          ResultSet rs = null;
          String statement=null;
          try {
              Connection conn = null;
      
              Class.forName("oracle.jdbc.driver.OracleDriver");
              conn = DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:xe", "smslib", "smslib");
      
              Statement s = conn.createStatement();
              statement = "Select \* from app\_"+keyword;
              rs = s.executeQuery(statement);
              Records r=null;
              while(rs.next())
              {
                  //String text =rs.getString("text");
                  //list.add(text);
                  r = new Records();
                  r.setNumber(rs.getLong("originator"));
                  r.setText(rs.getString("text"));
                  list.add(r);
              }
              s.close();
              conn.close();
              return (Records\[\])list.toArray(new Records\[list.size()\]);
              //return r;
      
          } catch (Exception ex) {
              ex.printStackTrace();
          }
          return null;
      }
      

      and my java file

      public class Records {

      private long number;
      private String text;
      
      public long getNumber()
      {
          return number;
      }
      public void setNumber(long num)
      {
          this.number = num;
      }
      
      public String getText()
      {
          return text;
      }
      public void setText(String text)
      {
          this.text = text;
      }
      

      }

      This is my JSP that call the method

      <%
      try {
      org.me.sms.SMSWebServiceService service = new org.me.sms.SMSWebServiceService();
      org.me.sms.SMSWebService port = service.getSMSWebServicePort();
      java.lang.String username = "";
      java.lang.String password = "";
      java.lang.String keyword = "Temp";

      java.util.List<org.me.sms.Records> result = port.retrieveSMS(username, password, keyword);
      
      
          out.println("Result = "+result);
      
      } catch (Exception ex) {
      
      }
      %>
      
      D Offline
      D Offline
      David Skelly
      wrote on last edited by
      #2

      Please don't take this the wrong way, but you really need to read a basic introduction to Java if you don't know how to work with arrays. http://java.sun.com/docs/books/tutorial/java/nutsandbolts/arrays.html[^]

      B 1 Reply Last reply
      0
      • D David Skelly

        Please don't take this the wrong way, but you really need to read a basic introduction to Java if you don't know how to work with arrays. http://java.sun.com/docs/books/tutorial/java/nutsandbolts/arrays.html[^]

        B Offline
        B Offline
        benjamin yap
        wrote on last edited by
        #3

        I do know how to access an array. But my code does it in a different way. First it adds my Record object into an arraylist called list and it returns this

        return (Records[])list.toArray(new Records[list.size()]);

        The above code i took from some tutorial that teach me how to return a database record into a WEB SERVICE method. In my client index.jsp, i consume the web service with the following code

        org.me.sms.SMSWebServiceService service = new org.me.sms.SMSWebServiceService();
        org.me.sms.SMSWebService port = service.getSMSWebServicePort();
         // TODO initialize WS operation arguments here
        java.lang.String username = "";
        java.lang.String password = "";
        java.lang.String keyword = "Temp";
        // TODO process result here
        java.util.List<org.me.sms.Records> result = port.retrieveSMS(username, password, keyword);
        
            //result = org.me.sms.Records(result);
        //out.println("Result = "+((org.me.sms.Records)result).getText());
        
            out.println("Result = "+result);
        

        I could not access the methods in my Records class. I tried out.println("Result = "+result.getText); but it wont work

        D 1 Reply Last reply
        0
        • B benjamin yap

          I do know how to access an array. But my code does it in a different way. First it adds my Record object into an arraylist called list and it returns this

          return (Records[])list.toArray(new Records[list.size()]);

          The above code i took from some tutorial that teach me how to return a database record into a WEB SERVICE method. In my client index.jsp, i consume the web service with the following code

          org.me.sms.SMSWebServiceService service = new org.me.sms.SMSWebServiceService();
          org.me.sms.SMSWebService port = service.getSMSWebServicePort();
           // TODO initialize WS operation arguments here
          java.lang.String username = "";
          java.lang.String password = "";
          java.lang.String keyword = "Temp";
          // TODO process result here
          java.util.List<org.me.sms.Records> result = port.retrieveSMS(username, password, keyword);
          
              //result = org.me.sms.Records(result);
          //out.println("Result = "+((org.me.sms.Records)result).getText());
          
              out.println("Result = "+result);
          

          I could not access the methods in my Records class. I tried out.println("Result = "+result.getText); but it wont work

          D Offline
          D Offline
          David Skelly
          wrote on last edited by
          #4

          In the above JSP, result is defined as a List. A List is not an array. Even if it was an array, your code wouldn't work the way you seem to expect. Consider the following:

          String[] myArray = { "a", "b", "c" };
          System.out.println("myArray = " + myArray);

          If you know about arrays, you will know that this does not show you the contents of myArray. Try it and see what it does. I recommend that you read up about arrays and collections.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups