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

📄 newsassiimpl.java

📁 JSP编写的汽车门户系统
💻 JAVA
字号:
/**
 *  (c) Copyright 2007 computer01
 *
 *   FILENAME     :  NewsAssiImpl.java
 *   PACKAGE      :  com.computer03.entitysupport
 *   CREATE DATE  : 2007-12-28
 *   AUTHOR       :  admin
 *   DESCRIPTION  : new assi impl 
 */
package com.computer03.entitysupport;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.computer03.common.Linkdb;
import com.computer03.entity.AllEntity;
import com.computer03.entity.TAB_CLASS;
import com.computer03.entity.TAB_NEWS;
import com.computer03.entity.TAB_STUDENTS;

public class NewsAssiImpl extends TAB_NEWS
implements EntityAssiInterface {
	/**
	 * 数据库操作类
	 */
	Linkdb linkdb = null;
	/**
	 * 通过页码返回当前页的学生实体列表
	 * @param condition 查询条件
	 * @param pageno 页码 第几页
	 * @param pernum 每一页记录数
	 * @return
	 */
	public List getStuEntListByPageno(
			AllEntity condition,
			int pageno,
			int pernum){
		List<AllEntity> allentlist = 
			new ArrayList<AllEntity>();
		List<AllEntity> pageentlist = 
			new ArrayList<AllEntity>();//当前页记录
		allentlist = 
			this.getEntityList(condition);
		int allentlen = 
			allentlist.size();//所有记录数
		int pagestart = 0;//开始记录数
		pagestart = 
			(pageno-1)*pernum;
		for(int i = 0;
		i < pernum&&(i+pagestart)<allentlen;
		i++){
			pageentlist.add(
					allentlist.get(i+pagestart));
		}
		return pageentlist;
	}
	/**
	 * 返回学生实体信息列表
	 */
	public List<AllEntity> getEntityList(AllEntity condition) {
		// TODO Auto-generated method stub
		List<AllEntity> allEntityList = new ArrayList<AllEntity>();
		try{
			linkdb = new Linkdb();
			/**
			 * sql
			 */
			StringBuffer buff =
				new StringBuffer();
			buff.append("select stu.STUNO,stu.STUNAME")
			.append(",stu.CLASSNO,cla.CLASSNAME,stu.PWD")
			.append(" from tab_students stu,tab_class cla")
			.append(
					" where stu.CLASSNO=cla.CLASSNO");
			/***
			 * 查询条件连接
			 */
			TAB_STUDENTS stu = 
				condition.getStudent();
			if(stu!=null){
			//根据学号查询
			if(stu.getSTUNO()!=null
					&&!"".equals(stu.getSTUNO())){}
			buff.append(" and stu.STUNO = '");
			buff.append(stu.getSTUNO()+"'");
			}
			buff.append(" order by stu.STUNO");
			ResultSet rs =
			linkdb.executeQuery(buff.toString());
			while(rs.next()){
				AllEntity allentity =
					new AllEntity();
				TAB_STUDENTS student = new TAB_STUDENTS();
				 student.setSTUNO(rs.getString(1));
				 student.setSTUNAME(rs.getString(2));
				 student.setPWD(rs.getString(5));
				 
				 TAB_CLASS tabcla = new TAB_CLASS();
				 tabcla.setCLASSNO(
						 new Integer(rs.getShort(3)));
				 tabcla.setCLASSNAME(rs.getString(4));
				 student.setPK_TABCLASS(tabcla);
				 allentity.setStudent(student);
				 
				 allEntityList.add(allentity); 
			}
		}catch(Exception e){
			e.printStackTrace();
		}
		return allEntityList;
	}
	/**
	 * 删除学生实体信息
	 * 要求:学生学号不能为空
	 */
	public void deleteEntity(AllEntity condition) {
		try{
			linkdb = new Linkdb();
			StringBuffer buff =
				new StringBuffer();
			buff.append("delete from tab_students");
			buff.append(" where STUNO='"
				+condition.getStudent().getSTUNO()
				+"'");
			linkdb.executeUpdate(buff.toString());
			linkdb.closeStmt();
			linkdb.closeConn();
		}catch(SQLException e){
			e.printStackTrace();
		}
	}
	/**
	 * 增加学生信息
	 * @throws Exception 
	 */
	public void saveEntity(AllEntity allentity) 
	throws Exception {
		// TODO Auto-generated method stub
		TAB_STUDENTS stu = allentity.getStudent();
		try{
			linkdb = new Linkdb();
			StringBuffer buff =
				new StringBuffer();
			buff.append("insert into tab_students ")
			.append("values('" +
					stu.getSTUNO()+
					"','" +
					stu.getSTUNAME()+
					"',"+
					stu.getPK_TABCLASS().getCLASSNO()+")");
			linkdb.executeUpdate(buff.toString());
			//System.out.println("插入成功"+buff.toString());
			linkdb.closeStmt();
			linkdb.closeConn();
		}catch(Exception e){
			System.out.println(
					"saveEntity捕获异常:"+
					e.toString());
			throw e;
		} 
	}
	/**
	 * 更新学生信息
	 */
	public int updateEntity(AllEntity allentity) {
		try{
			linkdb = new Linkdb();
			TAB_STUDENTS stu = 
				allentity.getStudent();
			StringBuffer buff = 
				new StringBuffer();
			buff.append("UPDATE tab_students")
			.append(" SET STUNAME='")
			.append(stu.getSTUNAME()+"',")
			.append(" CLASSNO=")
			.append(stu.getPK_TABCLASS()
					.getCLASSNO().intValue())
			.append(" WHERE STUNO='"
					+stu.getSTUNO()+"';");
			linkdb.executeUpdate(buff.toString());
			linkdb.closeStmt();
			linkdb.closeConn();
		}catch(SQLException e){
			e.printStackTrace();
		}
		return 1;
	}
}

⌨️ 快捷键说明

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