⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 storeaccessdaoimpl.java

📁 使用J2EE编写的网上商店系统
💻 JAVA
字号:
/*
 * 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;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -