I use Class.forname("net.sourceforge.jtds.jdbc.driver") to connect to MSSQL Server2008
public class ButtonTest extends AppCompatActivity {
private static String ip = "xxx.xxx.xxx.xxx";
private static String port = "1433";
private static String Classes = "net.sourceforge.jtds.jdbc.Driver";
private static String database = "database ";
private static String username = "username ";
private static String password = "password ";
private static String url = "jdbc:jtds:sqlserver://"+ip+":"+port+"/"+database;
private Connection connection = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test);
}
public void dbconn(View view) {
TextView txtview = (TextView) findViewById(R.id.textView);
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
try {
Class.forName(Classes);
connection = DriverManager.getConnection(url , username , password);
if (connection!=null){
Statement statement = null;
try {
statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery("Select * from Test where ID=3 ;");//
if (resultSet.next()){
txtview.setText(resultSet.getString("Column01"));
}
} catch (SQLException e) {
e.printStackTrace();
}
}
else {
}
} catch (SQLException | ClassNotFoundException e) {
e.printStackTrace();
}
}
it is working well when i test it on the VAD. but when i build the bundle and publish it on Google Play store it doesn't work error: ClassNotFoundexception