Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package exercise3Lib_8140058;
- import java.sql.*;
- import java.io.*;
- public class UserDAO_EX3_8140058 {
- private String errorMessages = "";
- private PreparedStatement stmt = null;
- private ResultSet rs = null;
- private Connection con = null;
- private final String userQuery = "select username from user_8xxxxxx where username =? and password=?";
- private String usern, passw, email;
- public User authenticateUser(String username, String password) throws Exception {
- DB_EX3_8140058 dataB = new DB_EX3_8140058();
- dataB.open();
- con = dataB.getConnection();
- try {
- stmt = con.prepareStatement(userQuery);
- // replacing the first ? with username and the second ? with
- // password
- stmt.setString(1, username);
- stmt.setString(2, password);
- // execute query
- rs = stmt.executeQuery();
- int counter = 0;
- while (rs.next())
- counter++;
- if (counter == 1) {
- User userVal = new User(rs.getString("username"),rs.getString("password"),rs.getString("email"));
- stmt.close();
- rs.close();
- con.close();
- dataB.close();
- return userVal;
- } else {
- stmt.close();
- rs.close();
- con.close();
- dataB.close();
- throw new Exception("Wrong username or password");
- }
- } catch (SQLException ex) {
- ex.printStackTrace();
- }
- }
- }
- Compile Error:
- C:\Users\JIM\Desktop\exercise3Lib_8140058\UserDAO_EX3_8140058.java:59: error: missing return statement
- }
- ^
- 1 error
- Tool completed with exit code 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement