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

📄 avg_class.java

📁 本网站为学生管理网站
💻 JAVA
字号:
package students;
import java.sql.*;
public class Avg_class {
	public float fun(String str){
		Statement stmt=null;
		ResultSet rs = null;
		Statement stmt1=null;
		ResultSet rs1 = null;
		Connection con=null;
		int i=0;
		int j=0;
		float m=0;
		float result=0;
		float k=0;
		String []cro_id=new String[100];
		String []cro_value=new String[100];
		try{
			con = Database.connectToDb();
			String strSQL="select C.cro_id,C.cro_value from crouses C ";
			stmt = con.createStatement();
			rs = stmt.executeQuery(strSQL);
			while(rs.next()){
				cro_id[i]=rs.getString("cro_id");
				cro_value[i]=rs.getString("cro_value");
				i++;
			}
		}catch (SQLException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			if (con != null) {
				try {
					con.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
				con = null;
			}
		}
		try{
			con = Database.connectToDb();	
			String strSQL1="select S.ID,S.cro_id,S.degree from sel_crouses S,students D where S.ID=D.ID and D.Class='"+str+"班'";
			stmt1=con.createStatement();
			rs1 = stmt1.executeQuery(strSQL1);
			while(rs1.next()){
				for(j=0;j<cro_id.length;j++){
						if(rs1.getString("cro_id").equals(cro_id[j])){
							result+=Float.parseFloat(rs1.getString("degree"))*Float.parseFloat(cro_value[j]);
							k+=Float.parseFloat(cro_value[j]);
						}
					}
				
				m=result/k;
				
			}			
		}catch (SQLException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			if (con != null) {
				try {
					con.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
				con = null;
			}
		}
		return m;
	}
}

⌨️ 快捷键说明

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