Advertisement
Guest User

Untitled

a guest
Aug 16th, 2016
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. Context context;
  2. private SharedPreferences setingPreferences = context.getSharedPreferences("Settings", Activity.MODE_PRIVATE);
  3. String ip;
  4. String classs = "net.sourceforge.jtds.jdbc.Driver";
  5. String db = "ISTABLocalDB";
  6. String un = "test";
  7. String password = "test";
  8. @SuppressLint("NewApi")
  9. public Connection CONN() {
  10. ip = setingPreferences.getString("server", "");
  11. StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
  12. .permitAll().build();
  13. StrictMode.setThreadPolicy(policy);
  14. Connection conn = null;
  15. String ConnURL = null;
  16. try {
  17. Class.forName(classs);
  18. ConnURL = "jdbc:jtds:sqlserver://" + ip + ";"
  19. + "databaseName=" + db + ";user=" + un + ";password="
  20. + password + ";";
  21. conn = DriverManager.getConnection(ConnURL);
  22. } catch (SQLException se) {
  23. Log.e("ERRO", se.getMessage());
  24. } catch (ClassNotFoundException e) {
  25. Log.e("ERRO", e.getMessage());
  26. } catch (Exception e) {
  27. Log.e("ERRO", e.getMessage());
  28. }
  29. return conn;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement