Advertisement
Guest User

Untitled

a guest
Nov 1st, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.57 KB | None | 0 0
  1. String ip, db, un, passwords;
  2. Connection con;
  3. PreparedStatement stmt;
  4. ResultSet rs;
  5.  
  6. public void MarcadoreBdd(GoogleMap map) {
  7. ip = "mssql4.gear.host";
  8. db = "ciclomapp1";
  9. un = "ciclomapp1";
  10. passwords = "Mk36-9DX-580";
  11.  
  12. String query = "select ru.nombre , ru.descripcion , avg(va.valoracion) ,re.tipo, ru.ubicacion n" +
  13. "from (Rutas ru inner join valorar va on ru.nombre=va.nombre_ruta) n" +
  14. "inner join reporte re on re.nombre_ruta =Ru.nombren" +
  15. "group by ru.nombre,ru.descripcion , va.valoracion ,re.tipo, ru.ubicacion; ";
  16. try {
  17. con = connectionclass(un, passwords, db, ip);
  18. stmt = con.prepareStatement(query);
  19. rs = stmt.executeQuery();
  20. while (rs.next()) {
  21. Ruta b = null;
  22. b.nombre = rs.getString("nombre");
  23. b.descripcion= rs.getString("descripcion");
  24. b.ubicacion= rs.getString("ubicacion");
  25. b.valoracion=rs.getString("valoracion").toString();
  26. b.reporte=rs.getString("reporte");
  27. String [] point=b.ubicacion.split(",");
  28. double latitude = Double.parseDouble(point[0]);
  29. double longitude = Double.parseDouble(point[1]);
  30. LatLng location = new LatLng(latitude, longitude);
  31. String valorar=String.valueOf(b.getValoracion());
  32.  
  33. map.addMarker(new MarkerOptions().position(location).snippet(b.descripcion+ System.getProperty ("line.separator")+"Valoracion de la ruta"
  34. +valorar+System.getProperty ("line.separator")+"Estado de la ruta: Posible"+b.reporte));
  35. }
  36. } catch (SQLException e) {
  37.  
  38. e.printStackTrace();
  39.  
  40. }
  41. }
  42.  
  43. @SuppressLint("NewApi")
  44. public Connection connectionclass (String user, String password, String database, String server){
  45. StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
  46. StrictMode.setThreadPolicy(policy);
  47. Connection connection = null;
  48. String ConnectionURL = null;
  49. try {
  50. Class.forName("net.sourceforge.jtds.jdbc.Driver");
  51. ConnectionURL = "jdbc:jtds:sqlserver://" + server + "/" + database + ";user=" + user + ";password=" + password + ";";
  52. connection = DriverManager.getConnection(ConnectionURL);
  53. } catch (SQLException se) {
  54. Log.e("error here 1 : ", se.getMessage());
  55. } catch (ClassNotFoundException e) {
  56. Log.e("error here 2 : ", e.getMessage());
  57. } catch (Exception e) {
  58. Log.e("error here 3 : ", e.getMessage());
  59. }
  60. return connection;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement