Developer's Daily Java Education - Test Projects
  front page | java | perl | unix | DevDirectory
   
Front Page
Java
Education
   
 


package com.missiondata.dbtest.container;

import com.missiondata.dbtest.model.User;
import java.sql.*;

public class UserContainer
{

  private static User getFromResultSet (ResultSet r)
  throws SQLException
  {
    User user = new User();
    user.setUsername( r.getString("username") );
    user.setPassword( r.getString("password") );
    user.setEmail( r.getString("email") );
    return user;
  }

  public static User getUserByName (Connection conn, String username)
  throws SQLException
  {
    User user = null;
    String query = "SELECT username,password,email FROM user"
                 + " WHERE username = '"
                 + username + "'";

    Statement st = conn.createStatement();
    ResultSet r = st.executeQuery(query);
    if ( r.next() )
    {
      user = getFromResultSet(r);
    }
    return user;
  }
}
Copyright 1998-2003 DevDaily Interactive, Inc.
All Rights Reserved.