ORCentral

src/eu/coform/database/command/CheckLoginDBCommand.java

Go to the documentation of this file.
00001 package eu.coform.database.command;
00002 
00003 import java.sql.ResultSet;
00004 import java.sql.SQLException;
00005 
00006 
00007 import eu.coform.database.DBException;
00008 import eu.coform.database.Database;
00009 import eu.coform.database.Query;
00010 import eu.coform.database.DBException.Error;
00011 
00015 public class CheckLoginDBCommand implements MultipleResultDatabaseCommand {
00016 
00017    private String userName;
00018    private long userId;
00019    private String password;
00020 
00021    public CheckLoginDBCommand(String uName) {
00022            userName = uName;
00023    }
00024 
00025    public Long getUserIdResult() {
00026 
00027            return new Long(userId);
00028    }
00029 
00030    public String getPasswordResult() {
00031            return password;
00032    }
00033    
00034    @Override
00040    public void exec() throws DBException {
00041       Query query = Database.getInstance().getNewQuery();
00042 
00043      
00044       query.setQuery ("SELECT ID, Password FROM user WHERE Username = \"" + userName + "\"");
00045       ResultSet rs = Database.getInstance().query(query);
00046 
00047       try {
00048          if (rs.next()) {
00049              password = rs.getString("Password");
00050              userId = rs.getInt("ID");
00051 
00052          }
00053          else
00054          {
00055              throw new DBException(Error.ObjectNotFound);
00056          }
00057 
00058       } catch (SQLException e) {
00059          e.printStackTrace();
00060          throw new DBException(Error.QueryInvalid);
00061       }
00062 
00063 
00064    }
00065 
00066 }
 All Classes Namespaces Files Functions Variables Enumerations