I am doing SqlServer2008 r2 connectivity with android.
My code is as follows:
public class MainActivity extends Activity {
String url="jdbc:sqlserver://localhost;instance=14GRAFICALI\\MSSQLSERVER2008;databaseName=AndroidDB;integrated security=true";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView tvData=(TextView)findViewById(R.id.tvSelectedData);
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance();
Connection conn =DriverManager.getConnection(url);
System.out.println("connected");
Statement statement=conn.createStatement();
ResultSet resultSet=statement.executeQuery("select * from AndroidDB");
while(resultSet.next()){
tvData.setText(" Data1 : "+resultSet.getString(1)+" Data 2 : "+resultSet.getNString(2));
}
} catch (Exception e) {
e.printStackTrace();
}
}
This code is not working and giving me error on line:
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance();
Error:
java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver
But when i checked this path, file was there with above path.
Have a look at it:
What can be the problem?
Please help me.
EDIT
Javabuildpath:
Libs: