Guest User

Untitled

a guest
Nov 9th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. package com.example.lenovo.testing1;
  2.  
  3. import android.annotation.SuppressLint;
  4. import android.os.StrictMode;
  5. import android.util.Log;
  6.  
  7. import java.sql.*;
  8.  
  9. public class ConnectionClass {
  10. String hostName = "haozailai.database.windows.net";
  11. String dbName = "haozailai";
  12. String user = "username";
  13. String password = "password";
  14.  
  15. @SuppressLint("NewApi")
  16. public Connection CONN() {
  17. StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
  18. StrictMode.setThreadPolicy(policy);
  19. String ConnURL;
  20. Connection conn = null;
  21.  
  22. try {
  23.  
  24. Class.forName("net.sourceforge.jtds.jdbc.Driver");
  25. String url = String.format("jdbc:jtds:sqlserver://haozailai.database.windows.net:1433;database=haozailai;user=username;password=password;encrypt=true;trustServerCertificate=false;hostNameInCertificate=*.database.windows.net;loginTimeout=30;");
  26. conn = DriverManager.getConnection(url);
  27.  
  28. }catch (SQLException se)
  29. {
  30. Log.e("error here 1 : ", se.getMessage());
  31. }
  32. catch (ClassNotFoundException e)
  33. {
  34. Log.e("error here 2 : ", e.getMessage());
  35. }
  36. catch (Exception e)
  37. {
  38. Log.e("error here 3 : ", e.getMessage());
  39. }
  40.  
  41.  
  42. return conn;
  43.  
  44.  
  45. }
  46. }
Add Comment
Please, Sign In to add comment