this is my layout.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/t1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/t2"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/t3"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/t4"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/t5"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btn2"
/>
</LinearLayout>
this is my activitymain.java
package com.example.mssqlconnect;
import android.os.Bundle;
import java.sql.*;
import net.sourceforge.jtds.jdbc.*;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import java.sql.*;
import net.sourceforge.jtds.jdbc.*;
public class MainActivity extends Activity {
public class A implements OnClickListener {
@Override
public void onClick(View arg0) {
TextView tv2=(TextView)findViewById(R.id.t2);
TextView tv3=(TextView)findViewById(R.id.t3);
TextView tv4=(TextView)findViewById(R.id.t4);
TextView tv5=(TextView)findViewById(R.id.t5);
tv2.setText("Connected");
Log.i("Android"," MySQL Connect Example.");
Connection conn = null;
try {
String driver = "net.sourceforge.jtds.jdbc.Driver";
Class.forName(driver).newInstance();
tv4.setText("2111");
//test = com.microsoft.sqlserver.jdbc.SQLServerDriver.class;
String connString = "jdbc:jtds:sqlserver://sony-VAIO/sony :1433/androiddata;encrypt=false;user=0cool;password=chevron;instance=SQLEXPRESS;";
//String connString ="jdbc:jtds:sqlserver://(local);instance=MSSQLSERVER";
String username = "0cool";
String password = "chevron";
tv4.setText("222222222");
try{
conn = DriverManager.getConnection(connString,username,password);
//tv5.setText("2423424");
Log.w("Connection","open");
Statement stmt = conn.createStatement();
ResultSet reset = stmt.executeQuery("select * from android_data");
//Print the data to the console
while(reset.next()){
Log.w("Data:",reset.getString(1));
// Log.w("Data",reset.getString(2));
//tv.setText(reset.getString(2));
}
conn.close();
}
catch(SQLException e)
{
tv5.setText(e.getMessage());
}
} catch (Exception e)
{
//Log.w("Error connection","" + e.getMessage());
TextView tv1=(TextView)findViewById(R.id.t1);
tv1.setText(e.getMessage());
}
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btn=(Button)findViewById(R.id.btn2);
btn.setOnClickListener(new A());
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
I am not getting any exception or any error in this code on running this in emulator help me pls m on a schedule. If there is an alternative for manipukating data in the database table then please guide me i have tried to access through json too but then again I was not getting any data back.