Advertisement
Guest User

Untitled

a guest
Mar 14th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. public class ConnectionClass
  2. {
  3. String ip = "192.168.1.4";
  4. String classs = "net.sourceforge.jtds.jdbc.Driver";
  5. String db = "BlackForestProd";
  6. String un = "sa";
  7. String password = "P@ss123";
  8.  
  9. @SuppressLint("NewApi")
  10. public Connection CONN()
  11. {
  12. StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
  13. StrictMode.setThreadPolicy(policy);
  14. Connection conn = null;
  15. String ConnURL = null;
  16. try
  17. {
  18. Class.forName(classs);
  19. ConnURL = "jdbc:jtds:sqlserver://" + ip + ";" + "databaseName=" + db + ";user=" + un + ";password=" + password + ";";
  20. conn = DriverManager.getConnection(ConnURL);
  21. }
  22. catch (SQLException se)
  23. {
  24. Log.e("ERRO", se.getMessage());
  25. }
  26. catch (ClassNotFoundException e)
  27. {
  28. Log.e("ERRO", e.getMessage());
  29. }
  30. catch (Exception e)
  31. {
  32. Log.e("ERRO", e.getMessage());
  33. }
  34. return conn;
  35. }
  36.  
  37. connectionClass = new ConnectionClass();
  38. Connection con = connectionClass.CONN();
  39. if (con == null) {
  40. z = "Error in connection with server";
  41. } else {
  42. Statement statement = con.createStatement();
  43. rs = statement.executeQuery("select Name from tblAppcustomer where Mobile='" + userid + "'");
  44. while (rs.next()) {
  45. clientname = rs.getString("Name");
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement