Advertisement
Guest User

Untitled

a guest
Jun 27th, 2016
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.08 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package main;
  7.  
  8. import java.sql.Connection;
  9. import java.sql.ResultSet;
  10. import java.sql.SQLException;
  11. import java.sql.Statement;
  12. import java.util.ArrayList;
  13. import java.util.List;
  14. import javax.naming.NamingException;
  15.  
  16. /**
  17. *
  18. * @author Illusion
  19. */
  20. public class user {
  21. Connection conn = null;
  22. String sql;
  23. Statement stmt = null;
  24. ResultSet rs;
  25. boolean found;
  26. public boolean checkUser(String user, String pass) throws Exception
  27. {
  28. try {
  29. sql = "SELECT * FROM user WHERE username='" + user + "' AND password='" + pass + "';";
  30. conn = db.getConn.getConnect();
  31. stmt = conn.createStatement();
  32. rs = stmt.executeQuery(sql);
  33. if (rs.next() == true) {
  34. System.out.print("found");
  35. found = true;
  36. } else {
  37. System.out.print("not found");
  38. found = false;
  39. }
  40. stmt.close();
  41. conn.close();
  42. }
  43. catch(SQLException e)
  44. {
  45. e.printStackTrace();
  46.  
  47. } catch (ClassNotFoundException e) {
  48. e.printStackTrace();
  49.  
  50. } catch (NamingException e) {
  51. e.printStackTrace();
  52.  
  53. }catch(Exception e) {
  54. e.printStackTrace();
  55. }
  56. return found;
  57. }
  58.  
  59.  
  60. List lista = new ArrayList();
  61. public List <Integer> getUsersList() throws Exception
  62. {
  63. try{
  64. sql = "SELECT iduser FROM user";
  65. conn = db.getConn.getConnect();
  66. stmt = conn.createStatement();
  67. rs = stmt.executeQuery(sql);
  68. while (rs.next()){
  69. lista.add(rs.getInt("iduser"));
  70. }
  71. stmt.close();
  72. conn.close();
  73. }
  74. catch(SQLException e)
  75. {
  76. e.printStackTrace();
  77.  
  78. } catch (ClassNotFoundException e) {
  79. e.printStackTrace();
  80.  
  81. } catch (NamingException e) {
  82. e.printStackTrace();
  83.  
  84. }
  85. return lista;
  86. }
  87. String name;
  88. public String getName(Integer id) throws Exception
  89. {
  90. try {
  91. sql = "SELECT * FROM user WHERE iduser='" + id + "';";
  92. conn = db.getConn.getConnect();
  93. stmt = conn.createStatement();
  94. rs = stmt.executeQuery(sql);
  95. if (rs.next() == true) {
  96. name = rs.getString("username");
  97. } else {
  98. System.out.print("not found");
  99. }
  100. stmt.close();
  101. conn.close();
  102. }
  103. catch(SQLException e)
  104. {
  105. e.printStackTrace();
  106.  
  107. } catch (ClassNotFoundException e) {
  108. e.printStackTrace();
  109.  
  110. } catch (NamingException e) {
  111. e.printStackTrace();
  112.  
  113. }catch(Exception e) {
  114. e.printStackTrace();
  115. }
  116. return name;
  117. }
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement