Advertisement
Guest User

Untitled

a guest
Apr 18th, 2016
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.99 KB | None | 0 0
  1. Metodo login
  2.  
  3. public static String login(String userid, String pswrd){
  4. String username = null;
  5. String Password = null;
  6. try {
  7. Class.forName("org.sqlite.JDBC");
  8. String dbURL = "jdbc:sqlite:/C:/Users/Alessandro/Desktop/db/HH_database.db";
  9. Connection conn = DriverManager.getConnection(dbURL);
  10. if (conn != null) {
  11. //GetUsername = JOptionPane.showInputDialog("Inserisci l'username");
  12. //GetPassword= JOptionPane.showInputDialog("Inserisci la password");
  13. Statement stmt = conn.createStatement();
  14. ResultSet rs;
  15. rs = stmt.executeQuery("SELECT Username, Password, Local_User_ID, Name, Surname FROM User_Data WHERE Username='" + userid + "' AND Password= '" + pswrd + "'");
  16. if(rs.next()){
  17. int Local_User_ID = rs.getInt("Local_User_ID");
  18. String Username = rs.getString("Username");
  19. ArrayList<String> res = new ArrayList<String>();
  20. ArrayList<Integer> res_1 = new ArrayList<Integer>();
  21. ArrayList<String> res_2 = new ArrayList<String>();
  22. String Name = rs.getString("Name");
  23. String Surname = rs.getString("Surname");
  24. rs = stmt.executeQuery("SELECT Device_Description, D.Local_Device_ID, Feature_ID_List FROM User_Device_Map U, Devices D WHERE U.Local_Device_ID=D.Local_Device_ID AND Local_User_ID= '" + Local_User_ID + "'");
  25. while(rs.next()){
  26. String Device = rs.getString("Device_Description");
  27. String Features_ID_List = rs.getString("Feature_ID_List");
  28. int ID = rs.getInt("Local_Device_ID");
  29. res.add(Device);
  30. res_1.add(ID);
  31. res_2.add(Features_ID_List);
  32. }
  33. d = new InfoDevice(res_1, res, res_2, Local_User_ID);
  34. u = new UtenteCurrent(Username, Password, res, res_1);
  35. return InfoDevice.toJson(Username, Local_User_ID, Name, Surname, res, res_1, res_2);
  36. }
  37.  
  38. conn.close();
  39. return "Username" + " " + userid + " " + "e" + " " + "Password" + " " + pswrd + " " + "Sbagliate";
  40. }
  41.  
  42. } catch (ClassNotFoundException ex) {
  43. ex.printStackTrace();
  44. } catch (SQLException ex) {
  45. ex.printStackTrace();
  46. }
  47. return "ciao";
  48. }
  49.  
  50. metodo toJson
  51.  
  52. public static String toJson(String Username, Integer Local_User_ID, String Name, String Surname, ArrayList <String> a, ArrayList <Integer> b, ArrayList <String> c)
  53. {
  54. String result = "{\r ";
  55. result+="\"Username\": \"" + Username + "\",\r ";
  56. result+="\"ID\": \"" + Local_User_ID + "\",\r ";
  57. result+="\"Nome\": \"" + Name + "\",\r ";
  58. result+="\"Cognome\": \"" + Surname + "\",\r ";
  59. result+="\"devices\": [\r ";
  60. for(int i=0;i<a.size();i++){
  61. result+=" {\r";
  62. result+=" \"name\": \""+ a.get(i)+ "\",\r";
  63. result+=" \"id\": \""+ b.get(i)+ "\",\r";
  64. result+=" \"features\": " + "[ "+c.get(i)+" ]\r";
  65. result+=" },\r";
  66. }
  67. result+=" ]\r}";
  68. return result;
  69. }
  70.  
  71. metodo POST
  72.  
  73. @POST
  74. @Produces({MediaType.APPLICATION_JSON})
  75. @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
  76. public String sayJSONQuery(
  77. @FormParam("id") String id,
  78. @FormParam("pswrd") String pswrd,
  79. @Context HttpServletResponse servletResponse) throws IOException {
  80. return UtenteCurrent.login(id, pswrd);
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement