0

I try to get the data from Web Service that I build with JAX-WS, WSDL and I want to implement in Android ListView.

This is my code in web service that I build on Netbeans.

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package in.figures.on.mobile;

import db.koneksi.dbKoneksi;
import java.sql.Statement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import org.json.simple.JSONValue;

/**
 *
 * @author Setyadi
 */
@WebService()
public class AksesData {

    /**
     * Web service operation
     */
    @WebMethod(operationName = "Lokasiku")
    public String Lokasiku(
            @WebParam(name = "lon") String lon,
            @WebParam(name = "lat") String lat) {
        //TODO write your implementation code here:

        dbKoneksi con = new dbKoneksi();
        Statement statement;
        String sql = "SELECT desa "
                + "FROM dki "
                + "WHERE ST_Within(ST_SetSRID(ST_MakePoint("+lon+","+lat+"),0),geom);";
        ResultSet hasil;
        String desa = null;

        try{
            statement = con.getConnection().createStatement();
            hasil = statement.executeQuery(sql);
            hasil.next();
            desa = hasil.getString(1);
        }
        catch(Exception e){
            desa = "desa_thegagals";
        }
        finally{

        }

        if (con != null)  {
            return desa;
        }
        else  {
            return "lokasiku_thegagals";
        }
    }

    /**
     * Web service operation
     */
    @WebMethod(operationName = "Kategori")
    public String Kategori() {
        //TODO write your implementation code here:

        dbKoneksi con = new dbKoneksi();
        Statement statement;
        Properties properties;
        List list = new ArrayList();
        String sql = "SELECT kategori FROM kategori ";
        ResultSet hasil;
        String kategori = null;

        try{
            statement = con.getConnection().createStatement();
            hasil = statement.executeQuery(sql);
            while (hasil.next()) {
                properties = new Properties();
                properties.put("kategori", hasil.getString(1));
                list.add(properties);
            }
            kategori = JSONValue.toJSONString(list);
        }
        catch(Exception e){
        }

        return kategori;
    }

}

Does anybody want to help me, at least give me a tutorial about this. Thanks in advance

AdityaSetyadi
  • 161
  • 1
  • 2
  • 18
  • Yes, I did, I used a sample web service code which returns a string with @ signs. Then I consume it in ANdroid with split the string from @s and store in a array "itemsList". But I have another problem, How can I do it with two different kind of data, like we implemenet the two dimensional Array, but I don't know how to do that. Thanks – AdityaSetyadi Jul 03 '12 at 11:20
  • I did't get your problem.will you explain or some example. – Sachin D Jul 03 '12 at 11:28
  • means you want return int,String,Date all these data types in 2 D array – Sachin D Jul 03 '12 at 11:34
  • Yap, I want to return two kind of data. String, int. Or even in the same data type String, String. How can I implement this on my Web Service? And about consume it on Android client? – AdityaSetyadi Jul 03 '12 at 11:46

2 Answers2

2

Android doesn't provide any support for SOAP web services. They prefer we useRESTful web services with XML or JSON. however there are a few SOAP libraries out there. KSOAP is very popular, I personally have had issues with it. http://ksoap2.sourceforge.net/

Another suggestion is icesoap. it is a very simple library to use and understand, it worked like a charm for me. http://code.google.com/p/icesoap/

greenkode
  • 4,001
  • 1
  • 26
  • 29
0

For return data in 2D array just get the data and convert it into String. Then store it in Array

rs = s.executeQuery();
ResultSetMetaData rsmd = rs.getMetaData();
colCount = rsmd.getColumnCount();
String[][] result;
result = new String[size][rsmd.getColumnCount()];

int j=0;
            while(rs.next()) 
            {

                for (int i = 1; i <= colCount; i++) 
                {

                    Object value=null;
                if(!rsmd.getColumnTypeName(i).matches("varchar"))
                {
                    if(rsmd.getColumnTypeName(i).matches("decimal"))
                        value=(Object)rs.getDouble(i);
                    else
                        value=(Object)rs.getObject(i);
                }
                    else
                    {
                        value = (Object)rs.getString(i);
                    }
                    if(value!=null)
                    {
                        result[j][i-1]=value.toString();
                    }
                    else
                    {
                        result[j][i-1]="--";
                    }
                }j++;
            }
        }
        catch (SQLException | ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

and In android phone toy need to get that array and convert it into appropriate data type.

If you going to display it then you can display as it is. No need to convert into its original data type.

Sachin D
  • 1,370
  • 7
  • 29
  • 42
  • Yes, I've tried it, but I dont know how to consume it in android. – AdityaSetyadi Jul 03 '12 at 17:32
  • Or, like this, I pass with JSON like this. how can I consume it, I try with JSONObject but stiil dont know how to use. Here is the JSON [{"id":"08.5670","name":"Aditya"},{"id":"11.1212","name":"Setyadi"}] Iwant to put it on Array two dimension. thanks Sachin for the attention, by the way. – AdityaSetyadi Jul 03 '12 at 19:01
  • I try to ask more completely in here http://stackoverflow.com/questions/11318761/json-android-listview – AdityaSetyadi Jul 03 '12 at 20:38
  • Sorry I don't know about Json.I can help you only about KSOAP. – Sachin D Jul 04 '12 at 06:47