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

📄 customerscoredao.java

📁 基于struts的网上商店源码
💻 JAVA
字号:
package com.mole.struts.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;

public class CustomerScoreDAO {
	private Connection conn;

	public CustomerScoreDAO() {
		try {
			Context ctx = new InitialContext();
			if (ctx == null)
				throw new Exception("Failed to initial context!");
			DataSource ds = (DataSource) ctx
					.lookup("java:comp/env/jdbc/crmdata");
			conn = ds.getConnection();
			conn.setAutoCommit(true);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	// 获取积分数量
	public int getCount(String LoginID, String end) {
		int count = 0;
		ResultSet rs = null;
		String sql = "SELECT COUNT(*) FROM v_CustomerScore a WHERE a.CustomerID="
				+ LoginID + end;
		try {
			rs = conn.prepareStatement(sql).executeQuery();
			if (rs.next())
				count = rs.getInt(1);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return count;
	}

	// 获取店铺信息
	public ArrayList<Object[]> getStore(String LoginID) throws Exception {
		String sql = "select distinct a.StoreName,a.StoreID from v_CustomerScore a where a.CustomerID='"
				+ LoginID + "'";
		ArrayList<Object[]> al = new ArrayList<Object[]>();
		PreparedStatement ps = null;
		ResultSet rs = null;
		try {
			ps = conn.prepareStatement(sql);
			rs = ps.executeQuery();
			while (rs.next()) {
				Object[] o = new Object[2];
				o[0] = rs.getString(1);
				o[1] = rs.getString(2);
				al.add(o);
			}
			return al;
		} finally {
			if (ps != null)
				ps.close();
		}
	}

	// 获取积分信息
	public ArrayList<Object[]> getScore(String LoginID, String end,
			int currentPage, int pageSize) throws Exception {
		ArrayList<Object[]> al = new ArrayList<Object[]>();
		PreparedStatement ps = null;
		ResultSet rs = null;
		String sql = "SELECT TOP "
				+ pageSize
				+ " a.CustomerName,a.StoreName,a.Score FROM v_CustomerScore a WHERE a.CustomerID="
				+ LoginID + end + " AND a.[ID] NOT IN (" + "SELECT TOP "
				+ (currentPage - 1) * pageSize
				+ " [ID] FROM [v_CustomerScore] WHERE a.CustomerID=" + LoginID
				+ end + ")";
		try {
			ps = conn.prepareStatement(sql);
			rs = ps.executeQuery();
			while (rs.next()) {
				Object[] o = new Object[3];
				o[0] = rs.getString(1);
				o[1] = rs.getString(2);
				o[2] = rs.getString(3);
				al.add(o);
			}
			return al;
		} finally {
			if (ps != null)
				ps.close();
		}
	}

}

⌨️ 快捷键说明

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