Advertisement
Guest User

Untitled

a guest
Dec 29th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 KB | None | 0 0
  1. import java.sql.*;
  2. import java.util.ArrayList;
  3.  
  4. public class ConnectBD {
  5. private Connection con;
  6. private Statement st;
  7. private ResultSet rs;
  8.  
  9.  
  10. public ConnectBD() {
  11. try {
  12. Class.forName("com.mysql.jdbc.Driver");
  13. con = DriverManager.getConnection("jdbc:mysql://localhost:3306/projectopdm", "root", "");
  14. st = con.createStatement();
  15. } catch (Exception e) {
  16. System.out.println("Error" + e);
  17. }
  18. }
  19.  
  20. public boolean testPW(String email,String passe){
  21. String query="Select password from utilizador where IDUtilizador='"+email+"'";
  22. try{
  23. rs=st.executeQuery(query);
  24. if(rs.next()){
  25. String passeword=rs.getString(1);
  26. return passe.equals(passeword);
  27. }
  28. }catch(Exception e){
  29. System.out.println("ERROR: "+e);
  30. }
  31. return false;
  32. }
  33.  
  34. public boolean inserirUser(String email,String nome,String passe,String dataNascimento){
  35. //
  36. return true;
  37. }
  38.  
  39. public ArrayList<String> conversasDoUser(String email){
  40. String query="select name from chat c,utilizadorchat u where c.IDChat=u.idchat and u.idutilizador='"+email+"'";
  41. ArrayList<String> chats = new ArrayList<>();
  42. try {
  43. rs = st.executeQuery(query);
  44. while (rs.next()){
  45. String aux=new String(rs.getString(1));
  46. chats.add(aux);
  47. }
  48. }catch(Exception e){
  49. System.out.println("ERROR: "+e);
  50. }
  51. return chats;
  52. }
  53.  
  54. public ArrayList<String> amigosDoUser(String email){
  55. //completar aqui
  56. String query="'"+email+"'";
  57. ArrayList<String> amigos = new ArrayList<>();
  58. try {
  59. rs = st.executeQuery(query);
  60. while (rs.next()){
  61. String aux=new String(rs.getString(1));
  62. amigos.add(aux);
  63. }
  64. }catch(Exception e){
  65. System.out.println("ERROR: "+e);
  66. }
  67. return amigos;
  68. }
  69.  
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement