StoreAccessDAOImpl.java
资源名称:MyStore.rar [点击查看]
上传用户:hgs128
上传日期:2007-02-03
资源大小:166k
文件大小:2k
源码类别:
百货/超市行业
开发平台:
WINDOWS
- /*
- * Created on 1999-5-17
- *
- * TODO To change the template for this generated file go to
- * Window - Preferences - Java - Code Generation - Code and Comments
- */
- package dao;
- import java.sql.Connection;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import javax.naming.InitialContext;
- import javax.sql.DataSource;
- /**
- * @author 28-9
- *
- * TODO To change the template for this generated type comment go to
- * Window - Preferences - Java - Code Generation - Code and Comments
- */
- public class StoreAccessDAOImpl implements StoreAccessDAO,StoreAccessStateDAO{
- private DataSource jdbcFactory;
- /* (non-Javadoc)
- * @see ado.StoreAccessDAO#init()
- */
- public void init() {
- // TODO Auto-generated method stub
- System.out.println("Entering StoreAccessDAOImpl.init()");
- InitialContext c=null;
- if(this.jdbcFactory==null){
- try {
- c=new InitialContext();
- this.jdbcFactory=(DataSource)c.lookup("java:comp/env/jdbc/OracleDS");
- } catch (Exception e) {
- // TODO: handle exception
- System.out.println("Error in StoreAccessDAOImpl.init()");
- }
- }
- System.out.println("Leaving StoreAccessDAOImpl.init()");
- }
- /* (non-Javadoc)
- * @see ado.StoreAccessDAO#loginUser(java.lang.String, java.lang.String)
- */
- public String loginUser(String username, String password) {
- // TODO Auto-generated method stub
- System.out.println("Entering StoreAccessDAOImpl.loginUser()");
- Connection conn=null;
- PreparedStatement ps=null;
- ResultSet rs=null;
- String userID=null;
- try {
- conn=jdbcFactory.getConnection();
- String queryString="select userid from storeaccess where username=? and password=?;";
- ps=conn.prepareStatement(queryString);
- ps.setString(1, username);
- ps.setString(2, password);
- rs=ps.executeQuery();
- boolean result=rs.next();
- if(result){
- userID=rs.getString("userid");
- System.out.println("User ID is: "+userID);
- }
- } catch (SQLException e) {
- // TODO: handle exception
- e.printStackTrace();
- System.out.println("Inside StoreAccessDAOImpl.loginUser()"+e);
- }finally{
- try {
- rs.close();
- ps.close();
- conn.close();
- } catch (Exception e) {
- // TODO: handle exception
- }
- }
- System.out.println("Leaving StoreAccessDAOImpl.loginUser()");
- return userID;
- }
- }