Advertisement
Guest User

Untitled

a guest
Jun 30th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. package de.CCIL.appServer;
  2.  
  3. import javax.ws.rs.GET;
  4. import javax.ws.rs.Path;
  5. import javax.ws.rs.PathParam;
  6. import javax.ws.rs.Produces;
  7. import javax.ws.rs.QueryParam;
  8. import javax.ws.rs.core.MediaType;
  9.  
  10. import de.CCIL.appServer.general.UserOnRadar;
  11.  
  12. import java.sql.*;
  13.  
  14. // POJO, no interface no extends
  15.  
  16. //Sets the path to base URL + /hello
  17. @Path("/Position/{UID}")
  18. public class Position {
  19.  
  20. @GET
  21. @Produces(MediaType.APPLICATION_JSON)
  22. public void updatePosition(@PathParam("UID") int UID,@QueryParam("lat") double lat,@QueryParam("lng") double lng,@QueryParam("acc") double acc) {
  23.  
  24. Statement stmt;
  25. try {
  26. Class.forName("com.mysql.jdbc.Driver");
  27. String url =
  28. "jdbc:mysql://localhost:3306/mydb";
  29. Connection con = DriverManager.getConnection(
  30. url,"root", "edHyFWdT");
  31. stmt = con.createStatement();
  32. Timestamp tstamp = new Timestamp(System.currentTimeMillis());
  33. stmt.executeUpdate("INSERT INTO tbl_positions VALUES(" + UID + ",'"+ tstamp.getTime() + "'," + lat + "," + lng + "," + acc + ")");
  34. stmt.executeUpdate("UPDATE tbl_user SET Lng="+ lng + ", Lat=" + lat + ",Accuracy=" + acc + ", Timestamp='" + tstamp.getTime() + "' WHERE UID=" + UID);
  35. } catch (Exception e){
  36.  
  37. System.out.println("Error " + e.getMessage());
  38. }
  39.  
  40. }
  41.  
  42.  
  43. @GET
  44. @Path("/Radar")
  45. @Produces(MediaType.APPLICATION_JSON)
  46. public UserOnRadar getUser(@PathParam("UID") int UID) {
  47.  
  48. UserOnRadar userOnRadar=new UserOnRadar();
  49. userOnRadar.addUser(3, "testbuddy", 47.4277, 9.38);
  50.  
  51. Statement stmt;
  52. try {
  53. Class.forName("com.mysql.jdbc.Driver");
  54. String url =
  55. "jdbc:mysql://localhost:3306/mydb";
  56. Connection con = DriverManager.getConnection(
  57. url,"root", "edHyFWdT");
  58. stmt = con.createStatement();
  59. Timestamp tstamp = new Timestamp(System.currentTimeMillis());
  60.  
  61. userOnRadar.addUser(3, "testbuddy", 47.4277, 9.38);
  62. con.close();
  63.  
  64.  
  65. } catch (Exception e){
  66.  
  67. System.out.println("Error " + e.getMessage());
  68. }
  69. System.out.println("number of users: " + userOnRadar.getvUsername().length());
  70.  
  71. return userOnRadar;
  72. }
  73.  
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement