Guest User

Untitled

a guest
Aug 7th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.61 KB | None | 0 0
  1. import android.annotation.SuppressLint;
  2. import android.os.StrictMode;
  3. import android.util.Log;
  4. import java.sql.SQLException;
  5. import java.sql.Connection;
  6. import java.sql.DriverManager;
  7.  
  8. public class ConnectionClass {
  9. String ip = "IP_Address(for eg.192.168.5.60)";
  10. String classs = "net.sourceforge.jtds.jdbc.Driver";
  11. String db = "Andro";
  12. String un = "username";
  13. String password = "pwd";
  14. @SuppressLint("NewApi")
  15. public Connection CONN() {
  16. StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
  17. .permitAll().build();
  18. StrictMode.setThreadPolicy(policy);
  19. Connection conn = null;
  20. String ConnURL = null;
  21. try {
  22. Class.forName(classs);
  23. /* ConnURL = "jdbc:jtds:sqlserver://" + ip + "/"
  24. + "databaseName=" + db + ";user=" + un + ";password="
  25. + password + ";";*/
  26.  
  27. ConnURL= "jdbc:jtds:sqlserver://IP_Address(for eg.192.168.5.60)/databaseName=Andro;user=username;password=pwd;";
  28. conn = DriverManager.getConnection(ConnURL);
  29.  
  30.  
  31. } catch (SQLException se) {
  32. Log.e("ERRO", se.getMessage());
  33. } catch (ClassNotFoundException e) {
  34. Log.e("ERRO", e.getMessage());
  35. } catch (Exception e) {
  36. Log.e("ERRO", e.getMessage());
  37. }
  38. return conn;
  39. }
  40. }
  41.  
  42. @Override
  43. protected String doInBackground(String... params) {
  44. if(userid.trim().equals("")|| password.trim().equals(""))
  45. z = "Please enter User Id and Password";
  46. else
  47. {
  48. try {
  49. Connection con = connectionClass.CONN();
  50. if (con == null) {
  51. z = "Error in connection with SQL server";
  52. } else {
  53. heading.setText("u"+con.toString());
  54. String query = "select * from Usertbl where UserId='" + userid + "' and Password='" + password + "'";
  55.  
  56. Statement stmt = con.createStatement();
  57. heading.setText("After statement");
  58. ResultSet rs = stmt.executeQuery(query);
  59.  
  60. // heading.setText(rs.getString(1));
  61. z = "under else block";
  62. if(rs.next())
  63. {
  64. z = "Login successfull";
  65. isSuccess=true;
  66. }
  67. else
  68. {
  69. z = "Invalid Credentials";
  70. isSuccess = false;
  71. }
  72. }
  73. }
  74. catch (Exception ex)
  75. {
  76. isSuccess = false;
  77. z = "Exceptions";
  78. }
  79. }
  80. return z;
  81. }
Add Comment
Please, Sign In to add comment