Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package dbHelpers;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import model.User;
- public class ReadUserQuery {
- private Connection connection;
- private ResultSet results;
- private User user = new User();
- private int usernum;
- public ReadUserQuery(String dbName, String uName, String pwd) {
- String url = "jdbc:mysql://localhost:3306/" + dbName;
- try {
- Class.forName("com.mysql.jdbc.Driver").newInstance();
- this.connection = DriverManager.getConnection(url, uName, pwd);
- } catch (InstantiationException | IllegalAccessException | ClassNotFoundException | SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- public void ReadUserRecord(String txtusername) {
- String query = "SELECT usernum FROM User where userID = ?";
- try {
- PreparedStatement ps = connection.prepareStatement(query);
- ps.setString(1, txtusername);
- this.results = ps.executeQuery();
- this.results.next();
- user.setUsernum(this.results.getInt(1));
- // user.setUserID(this.results.getString("userID"));
- // user.setPassword(this.results.getString("password"));
- // user.setFname(this.results.getString("fname"));
- // user.setLname(this.results.getString("lname"));
- // user.setEmail(this.results.getString("email"));
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- public User getUser() {
- return this.user;
- }
- }
Add Comment
Please, Sign In to add comment