Hi everybody!
my problem is the following..i have a function so as to register a new User.i would like although first to chech if the username that the user specifies is already taken.the code is as follows:
public int saveUser(User user) throws ServiceException {
PreparedStatement preparedStatement = null;
PreparedStatement preparedStatement2;
int userId = 0;
Connection connection = null;
ResultSet resultSet = null;
ResultSet resultSet2;
try {
connection = dataSource.getConnection();
preparedStatement2 = connection.prepareStatement(SQL_usernameExists);
preparedStatement2.setString(1, user.getUserName());
resultSet2 = preparedStatement.executeQuery();
if (resultSet2 != null) {
userId=-1;
}
else if (resultSet2 == null) { //code for user registration//
what i am trying to do is to have this function returning -1 if this username already exists or registering the new user.but this code doesnt seem to work!it is caught in a ServiceException.
the sql_query i use to check if the username already exists is :
private static final
String SQL_usernameExists = "select user_id from account where USERNAME=?";
can anyone help??