Guest User

Untitled

a guest
May 9th, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. package dbHelpers;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.PreparedStatement;
  6. import java.sql.ResultSet;
  7. import java.sql.SQLException;
  8.  
  9. import model.User;
  10.  
  11. public class ReadUserQuery {
  12.  
  13. private Connection connection;
  14. private ResultSet results;
  15.  
  16. private User user = new User();
  17. private int usernum;
  18.  
  19. public ReadUserQuery(String dbName, String uName, String pwd) {
  20. String url = "jdbc:mysql://localhost:3306/" + dbName;
  21.  
  22. try {
  23. Class.forName("com.mysql.jdbc.Driver").newInstance();
  24. this.connection = DriverManager.getConnection(url, uName, pwd);
  25. } catch (InstantiationException | IllegalAccessException | ClassNotFoundException | SQLException e) {
  26. // TODO Auto-generated catch block
  27. e.printStackTrace();
  28. }
  29. }
  30.  
  31. public void ReadUserRecord(String txtusername) {
  32. String query = "SELECT usernum FROM User where userID = ?";
  33.  
  34. try {
  35. PreparedStatement ps = connection.prepareStatement(query);
  36. ps.setString(1, txtusername);
  37.  
  38. this.results = ps.executeQuery();
  39.  
  40. this.results.next();
  41.  
  42. user.setUsernum(this.results.getInt(1));
  43. // user.setUserID(this.results.getString("userID"));
  44. // user.setPassword(this.results.getString("password"));
  45. // user.setFname(this.results.getString("fname"));
  46. // user.setLname(this.results.getString("lname"));
  47. // user.setEmail(this.results.getString("email"));
  48.  
  49.  
  50. } catch (SQLException e) {
  51. // TODO Auto-generated catch block
  52. e.printStackTrace();
  53. }
  54.  
  55. }
  56.  
  57. public User getUser() {
  58. return this.user;
  59. }
  60.  
  61. }
Add Comment
Please, Sign In to add comment