scoretable.java

来自「这是一个可以在手机客户端运行的选课系统 这个是客户端」· Java 代码 · 共 54 行

JAVA
54
字号
package jdbc;
import java.sql.*;

public class ScoreTable
{ 
	private String command=null;
	private Statement statement=null;
	
	public ScoreTable(Statement statement)
	{
		this.statement=statement;	
	}
	
	public int insert(String studentID,String courseName,int term,int compulsory,String score) throws SQLException
	{
		command="INSERT INTO ScoreTable VALUES ('"+studentID+"','"+courseName+"','"+term+"',"+compulsory+",'"+score+"')";
		return statement.executeUpdate(command);
	}
	
	public int delete(String studentID) throws SQLException
	{
		if (studentID==null)
			command="DELETE FROM ScoreTable";
		else
			command="DELETE FROM ScoreTable WHERE studnetID='"+studentID+"'";		
		return statement.executeUpdate(command);
	}
	
	public int update(String studentID,String courseName,int compulsory,int term,String score) throws SQLException
	{
		command="UPDATE ScoreTable SET courseName='"+courseName+"',compulsory="+compulsory+",term="+term+",score='"+score+"' WHERE studentID='"+studentID+"'";
		return statement.executeUpdate(command);	
	}
	
	public ResultSet select(String studentID,int term) throws SQLException
	{
		if(term==0)
			command="select * from scoretable where studentid='"+studentID+"'";
		else	
			command="select * from scoretable where studentid='"+studentID+"' and term="+term;
		return statement.executeQuery(command);
	}
	
	public int selectNum(String studentID,int term) throws SQLException
	{
		if(term==0)
			command="SELECT COUNT(*) FROM ScoreTable where studentID='"+studentID+"'";
		else
			command="SELECT COUNT(*) FROM ScoreTable where studentID='"+studentID+"' and term="+term;
		ResultSet rs=statement.executeQuery(command);
		rs.next();
		return rs.getInt(1);
	}
}

⌨️ 快捷键说明

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