Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package de.CCIL.appServer;
- import javax.ws.rs.GET;
- import javax.ws.rs.Path;
- import javax.ws.rs.PathParam;
- import javax.ws.rs.Produces;
- import javax.ws.rs.QueryParam;
- import javax.ws.rs.core.MediaType;
- import de.CCIL.appServer.general.UserOnRadar;
- import java.sql.*;
- // POJO, no interface no extends
- //Sets the path to base URL + /hello
- @Path("/Position/{UID}")
- public class Position {
- @GET
- @Produces(MediaType.APPLICATION_JSON)
- public void updatePosition(@PathParam("UID") int UID,@QueryParam("lat") double lat,@QueryParam("lng") double lng,@QueryParam("acc") double acc) {
- Statement stmt;
- try {
- Class.forName("com.mysql.jdbc.Driver");
- String url =
- "jdbc:mysql://localhost:3306/mydb";
- Connection con = DriverManager.getConnection(
- url,"root", "edHyFWdT");
- stmt = con.createStatement();
- Timestamp tstamp = new Timestamp(System.currentTimeMillis());
- stmt.executeUpdate("INSERT INTO tbl_positions VALUES(" + UID + ",'"+ tstamp.getTime() + "'," + lat + "," + lng + "," + acc + ")");
- stmt.executeUpdate("UPDATE tbl_user SET Lng="+ lng + ", Lat=" + lat + ",Accuracy=" + acc + ", Timestamp='" + tstamp.getTime() + "' WHERE UID=" + UID);
- } catch (Exception e){
- System.out.println("Error " + e.getMessage());
- }
- }
- @GET
- @Path("/Radar")
- @Produces(MediaType.APPLICATION_JSON)
- public UserOnRadar getUser(@PathParam("UID") int UID) {
- UserOnRadar userOnRadar=new UserOnRadar();
- userOnRadar.addUser(3, "testbuddy", 47.4277, 9.38);
- Statement stmt;
- try {
- Class.forName("com.mysql.jdbc.Driver");
- String url =
- "jdbc:mysql://localhost:3306/mydb";
- Connection con = DriverManager.getConnection(
- url,"root", "edHyFWdT");
- stmt = con.createStatement();
- Timestamp tstamp = new Timestamp(System.currentTimeMillis());
- userOnRadar.addUser(3, "testbuddy", 47.4277, 9.38);
- con.close();
- } catch (Exception e){
- System.out.println("Error " + e.getMessage());
- }
- System.out.println("number of users: " + userOnRadar.getvUsername().length());
- return userOnRadar;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement