array?
-
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) { } %>
-
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) { } %>
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[^]
-
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[^]
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
-
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
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.