0

I have to develop one android example.

Its performs the fetching data from mysql database and display on android application.

I have used below webservice code:

public class EditProfile {
public String customerData(String Username,String Password,String Firstname,String Lastname,String Company,String Taxnumber,String Baddress,String Bcity,String Bstate,String Bcountry,String Bzipcode,String Saddress,String Scity,String Sstate,String Scountry,String Szipcode,String Email,String Phone,String Fax,String Url){

 String customerInfo = "";

try{

Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://10.0.0.75:3306/xcart432pro","root","");
 PreparedStatement statement =  con.prepareStatement("SELECT * FROM xcart_customers where login = '"+Username+"'");
 ResultSet result = statement.executeQuery();

while(result.next()){
            customerInfo = customerInfo + result.getString("login") + ":" +result.getString("password")+ ":" +result.getString("firstname")
    }

     }
     catch(Exception exc){
         System.out.println(exc.getMessage());
           }
        return customerInfo;
        }

I have used below android code:

 public class RetailerActivity extends Activity {
    private final String NAMESPACE = "http://xcart.com";
  private final String URL = "http://10.0.0.75:8085/XcartLogin/services/EditProfile?wsdl";
  private int i;
  private final String SOAP_ACTION = "http://xcart.com/customerData";
  private final String METHOD_NAME = "customerData";

  String str,mTitle;
  /** Called when the activity is first created. */
  @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
         try {
        SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); 
     SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);

     envelope.setOutputSoapObject(request);

     HttpTransportSE ht = new HttpTransportSE(URL);

       ht.call(SOAP_ACTION, envelope);

         SoapPrimitive s = response;
        str = s.toString();
       String[] words = str.split(":");
       TextView tv = (TextView) findViewById(R.id.user);
        tv.setText(Username);

      EditText tv1 = (EditText) findViewById(R.id.pass);


        tv1.setText(words[1].toString());
      EditText tv2 = (EditText) findViewById(R.id.tf_userName);


         tv2.setText(words[2].toString());

          for (int i = 0, l = words.length; i < l; ++i) {
                }}

       catch (Exception e) {
          e.printStackTrace();
           }
            }}

Here i have to run the app means fetching data from mysql database and display the data on android .but i didn't get the response.how can i get it.

Here i have to wrote the condition like static:

SELECT * FROM xcart_customers where login = 'mercy'"); means fetching the data from mysql database and display the data for that user.its successfully worked.

But i have write the code dynamically means

"SELECT * FROM xcart_customers where login = '"+Username+"'"); means

didn't get the response.please help me.

How can i develop these.give me solution or ideas for these.

2
  • What does logcat say? Not all of it, there might be an exception. Commented Jan 31, 2013 at 10:35
  • getting these error:01-31 10:37:41.846: I/ActivityManager(59): Displayed activity com.retailer.client/.RetailerActivity: 4469 ms (total 4469 ms) 01-31 10:37:46.697: D/SntpClient(59): request time failed: java.net.SocketException: Address family not supported by protocol Commented Jan 31, 2013 at 10:42

2 Answers 2

1

It could be that username variable doesn't hold a valid value, try to print it before you invoke the query, sayin that, i see you are using PreparedStatement, when using PreparedStatement you should use methods from PreparedStatement API along with the place holders in the query.

 PreparedStatement statement =  con.prepareStatement("SELECT * FROM xcart_customers where login = ?);
statement.setString(1, username);
 ResultSet result = statement.executeQuery();
Sign up to request clarification or add additional context in comments.

Comments

0

Not really an answer, but basically its bad practice as far as I know, to try and create a 1on1 connection with your external database (through jdbc or any other thinkable way).

This is not designed to handle all the things that can go horribly wrong on your device as result of losing connection etc.

You're much better off creating a little (REST i'd recommend) webservice to expose your database instead.

1 Comment

Here i have used JDBC and called WSDL webservice only.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.