I am getting problem in my application
Here is my piece of code my activity throwing an exception “Error Connection net.sourceforge.jtds.jdbc.Driver”
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
sync = (Button) findViewById(R.id.button1);
sync.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
// TODO Auto-generated method stub
query2(); }
});
}
public void query2()
{
Log.i("Android"," SQL Connect Example.");
Connection conn = null;
try {
String driver = "net.sourceforge.jtds.jdbc.Driver";
Class.forName(driver).newInstance();
//test = com.microsoft.sqlserver.jdbc.SQLServerDriver.class;
String connString = "jdbc:jtds:sqlserver://server_ip_address :198.168.0.10/tracebaledb;encrypt=fasle;user=sa;password=SqlServer2005;instance=SQLEXPRESS;";
String username = "sa";
String password = "SqlServer2005";
conn = DriverManager.getConnection(connString,username,password);
Log.w("Connection","open");
Statement stmt = conn.createStatement();
ResultSet reset = stmt.executeQuery("select * from AD_Login");
//Print the data to the console
while(reset.next()){
Log.w("Data:",reset.getString(3));
Log.w("Data",reset.getString(2)); }
conn.close();
} catch (Exception e)
{
Log.w("Error connection","" + e.getMessage());
}
}
}
You can connect to SQL Server databse throuh webservice.
Here is the sample code to call the webservice.
Make sure you set the permission in Manifest.xml file,
You can write the webservice in php or java to get this values and connect to SQL Server