Guest User

Untitled

a guest
Nov 8th, 2017
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. `package com.example.user.hello;
  2.  
  3. import android.annotation.SuppressLint;
  4. import android.app.Application;
  5. import android.os.StrictMode;
  6. import android.util.Log;
  7.  
  8. import java.sql.Connection;
  9. import java.sql.DriverManager;
  10. import java.sql.SQLException;
  11. public class db_class extends Application{
  12.  
  13. @SuppressLint("NewApi")
  14. static Connection ConnectionDB() {
  15. String url="jdbc:jtds:sqlserver://WIN-H2IOJKV9R76:1433:/Test;";
  16. String username="khiki";
  17. String password="12345";
  18.  
  19. StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
  20. StrictMode.setThreadPolicy(policy);
  21. java.sql.Connection connection = null;
  22. try{
  23. Class.forName("net.sourceforge.jtds.jdbc.Driver");
  24. connection = DriverManager.getConnection(url,username,password);
  25. }
  26. catch (SQLException se){
  27. Log.e("error from SQL",se.getMessage());
  28. }
  29. catch(ClassNotFoundException e){
  30. Log.e("Error from Class",e.getMessage());
  31. }
  32. catch (Exception ex){
  33. Log.e("Error from Exception",ex.getMessage());
  34. }
  35. return connection;
  36. }
  37.  
  38.  
  39.  
  40. }
  41. `
Add Comment
Please, Sign In to add comment