connecting mysql from android with jdbc

Posted by manuraphy on Stack Overflow See other posts from Stack Overflow or by manuraphy
Published on 2012-09-02T03:13:13Z Indexed on 2012/09/02 3:38 UTC
Read the original article Hit count: 1605

Filed under:
|
|

hai i used the following code to connect mysql in local host from android. it only displays the actions given in catch section . i dont know whether its a connection problem or not

package com.test1;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class Test1Activity extends Activity {
/** Called when the activity is first created. */
String str="new";
static ResultSet rs;
static PreparedStatement st;
static Connection con;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    final   TextView tv=(TextView)findViewById(R.id.user);

    try
    {
        Class.forName("com.mysql.jdbc.Driver");
          con=DriverManager.getConnection("jdbc:mysql://10.0.2.2:8080/example","root","");
        st=con.prepareStatement("select * from country where id=1");
        rs=st.executeQuery();
         while(rs.next())
         {
         str=rs.getString(2);


         }


    tv.setText(str);
    setContentView(tv);
    }
    catch(Exception e)
    {
        tv.setText(str);
    }
    }
}

when executes it displays "new" in the avd.

     java.lang.management.ManagementFactory.getThreadMXBean, referenced from method com.mysql.jdbc.MysqlIO.appendDeadlockStatusInformation


       Could not find class 'javax.naming.StringRefAddr', referenced from method com.mysql.jdbc.ConnectionPropertiesImpl$ConnectionProperty.storeTo


       Could not find method javax.naming.Reference.get, referenced from method com.mysql.jdbc.ConnectionPropertiesImpl$ConnectionProperty.initializeFrom

can anyone suggest some solution ? and thankz in advance

© Stack Overflow or respective owner

Related posts about android

Related posts about mysql