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

📄 scoreio.java

📁 成绩查询系统(学校期末的作业) Struts+jdbc+mysql+tomcat 开发工具为BEA WORKSHOP 功能无非就是增删查改加用户权限判断
💻 JAVA
字号:
package sfs.entity.io;

import java.lang.reflect.InvocationTargetException;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.List;

import sfs.connection.ConnIO;
import sfs.entity.Score;

public class ScoreIo extends ConnIO{

	public ScoreIo() throws ClassNotFoundException, SQLException {
		super();
	}
	/*******************查询***********************/
	public  List query() throws SQLException{
		String sql="select * from st_score";
		return super.Query(sql,"st_score");		
	}
	
	public  List queryByid(int id) throws SQLException, NumberFormatException, IllegalAccessException, InvocationTargetException, NoSuchMethodException{
		String sql="select * from st_score where id="+id;
		return super.Query(sql,"st_score");
	}
	
	public  List queryBynumber(String number) throws SQLException, NumberFormatException, IllegalAccessException, InvocationTargetException, NoSuchMethodException{
		String sql="select * from st_score where number="+number;
		return super.Query(sql,"st_score");
	}
	
	
	/**************************删除****************************/
	public  boolean deletByid(Score sc) throws SQLException, IllegalAccessException, InvocationTargetException, NoSuchMethodException{
		super.DeletById("st_score",sc);
		return true;
	}
	public  boolean deletBynumber(Score sc) throws SQLException, IllegalAccessException, InvocationTargetException, NoSuchMethodException{
		super.DeletByNumber("st_score",sc);
		return true;
	}
	
	/***********************增加或修改*************************/
	public  boolean saveorupdata(Score sc) throws SQLException, NumberFormatException, IllegalAccessException, InvocationTargetException, NoSuchMethodException{
		//查询对象,如果为空则增加,不为空则更新
		if(this.QueryById("st_score",sc)==null){			
			//增加记录
			System.out.print("增加记录");               
			String sql="insert  st_score (number,math,chinese,english,computer,politics,geography) values (?,?,?,?,?,?,?)";
			PreparedStatement prepar = conn.prepareStatement(sql);
			prepar.setString(1,sc.getNumber());
			prepar.setString(2,sc.getMath());
			prepar.setString(3,sc.getChinese());
			prepar.setString(4,sc.getEnglish());
			prepar.setString(5,sc.getComputer());
			prepar.setString(6,sc.getPolitics());
			prepar.setString(7,sc.getGeography());
			prepar.executeUpdate();
			prepar.close();	
			return true;
		}else{
			//更新			
			System.out.print("更新");               
			//是否需要按照用户名修改更新??
			Score temp=(Score)this.QueryById("st_score",sc).get(0);
			String sql="update st_score set number=? ,math=? ,chinese=? ,english=? ,computer=? ,politics=? ,geography=? where id=?";
			PreparedStatement prepar = conn.prepareStatement(sql);
			prepar.setString(1,sc.getNumber());
			prepar.setString(2,sc.getMath());
			prepar.setString(3,sc.getChinese());
			prepar.setString(4,sc.getEnglish());
			prepar.setString(5,sc.getComputer());
			prepar.setString(6,sc.getPolitics());
			prepar.setString(7,sc.getGeography());
			prepar.setInt(8,temp.getId());
			prepar.execute();
			prepar.close();	
			return true;
		}

	}
}

⌨️ 快捷键说明

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