Advertisement
Guest User

Untitled

a guest
Feb 17th, 2016
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.06 KB | None | 0 0
  1. package hitesh.sqlapp;
  2. import android.annotation.SuppressLint;
  3. import android.os.StrictMode;
  4. import android.util.Log;
  5. import java.sql.SQLException;
  6. import java.sql.Connection;
  7. import java.sql.DriverManager;
  8. /**
  9. * Created by h-pc on 16-Oct-15.
  10. */
  11. public class ConnectionClass {
  12. String ip = "192.168.0.100";
  13. String classs = "net.sourceforge.jtds.jdbc.Driver";
  14. String db = "Andro";
  15. String un = "hitesh";
  16. String password = "789";
  17. @SuppressLint("NewApi")
  18. public Connection CONN() {
  19. StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
  20. .permitAll().build();
  21. StrictMode.setThreadPolicy(policy);
  22. Connection conn = null;
  23. String ConnURL = null;
  24. try {
  25. Class.forName(classs);
  26. ConnURL = "jdbc:jtds:sqlserver://" + ip + ";"
  27. + "databaseName=" + db + ";user=" + un + ";password="
  28. + password + ";";
  29. conn = DriverManager.getConnection(ConnURL);
  30. } catch (SQLException se) {
  31. Log.e("ERRO", se.getMessage());
  32. } catch (ClassNotFoundException e) {
  33. Log.e("ERRO", e.getMessage());
  34. } catch (Exception e) {
  35. Log.e("ERRO", e.getMessage());
  36. }
  37. return conn;
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement