Guest User

Untitled

a guest
Nov 8th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 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. } catch (SQLException se) {
  26. Log.e("error from SQL",se.getMessage());
  27. } catch(ClassNotFoundException e) {
  28. Log.e("Error from Class",e.getMessage());
  29. } catch (Exception ex) {
  30. Log.e("Error from Exception",ex.getMessage());
  31. }
  32. return connection;
  33. }
  34. }
Add Comment
Please, Sign In to add comment