Advertisement
Guest User

Untitled

a guest
Apr 11th, 2016
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.53 KB | None | 0 0
  1. public static String login(){
  2. String Username = null;
  3. String Password = null;
  4. try {
  5. Class.forName("org.sqlite.JDBC");
  6. String dbURL = "jdbc:sqlite:/C:/Users/Alessandro/Desktop/db/HH_database.db";
  7. Connection conn = DriverManager.getConnection(dbURL);
  8. if (conn != null) {
  9. //GetUsername = JOptionPane.showInputDialog("Inserisci l'username");
  10. //GetPassword= JOptionPane.showInputDialog("Inserisci la password");
  11. Statement stmt = conn.createStatement();
  12. ResultSet rs;
  13. rs = stmt.executeQuery("SELECT Username, Password, Local_User_ID, Name, Surname FROM User_Data WHERE Username='" + Username + "' AND Password= '" + Password + "'");
  14. if(rs.next()){
  15. int id = rs.getInt("Local_User_ID");
  16. ArrayList<String> res = new ArrayList<String>();
  17. ArrayList<Integer> res_1 = new ArrayList<Integer>();
  18. ArrayList<String> res_2 = new ArrayList<String>();
  19. String nome = rs.getString("Name");
  20. String cognome = rs.getString("Surname");
  21. 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= '" + id + "'");
  22. while(rs.next()){
  23. String Device = rs.getString("Device_Description");
  24. String Features_ID_List = rs.getString("Feature_ID_List");
  25. int ID = rs.getInt("Local_Device_ID");
  26. res.add(Device);
  27. res_1.add(ID);
  28. res_2.add(Features_ID_List);
  29. }
  30. d = new InfoDevice(res_1, res, res_2, id);
  31. u = new UtenteCurrent(Username, Password, res, res_1);
  32. return InfoDevice.toJson(res, res_1, res_2);
  33. }
  34.  
  35. conn.close();
  36. return "Username" + " " + Username + " " + "e" + " " + "Password" + " " + Password + " " + "Sbagliate";
  37. }
  38.  
  39. } catch (ClassNotFoundException ex) {
  40. ex.printStackTrace();
  41. } catch (SQLException ex) {
  42. ex.printStackTrace();
  43. }
  44. return "ciao";
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement