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

📄 insert_kaoshichengji.java

📁 用来管理在校学生的出勤.作息等的管理系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:

		textField_2 = new JTextField();
		textField_2.setBounds(334, 273, 137, 22);
		getContentPane().add(textField_2);

		final JButton button_2 = new JButton();
		button_2.setFont(new Font("", Font.PLAIN, 14));
		button_2.addActionListener(new ActionListener() {
			public void actionPerformed(final ActionEvent e) {

				String sql = "update 成绩表 set  考试成绩='"
						+ textField_2.getText().trim() + "' where 学号='"
						+ textField_1.getText().trim() + "'";

				// System.out.println(sql);
				try {
					int result = JOptionPane.showOptionDialog(null,
							"是否对数据进行修改?", "系统提示", JOptionPane.YES_NO_OPTION,
							JOptionPane.QUESTION_MESSAGE, null, new String[] {
									"是", "否" }, "否");
					if (result == JOptionPane.OK_OPTION) {
						try{
							Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
							Connection con = DriverManager
									.getConnection("jdbc:odbc:DB_Student");
							Statement stm = con.createStatement();
							
							if (stm.executeUpdate(sql) != 0)
								JOptionPane.showMessageDialog(null, "数据修改成功!",
										"系统提示!", JOptionPane.INFORMATION_MESSAGE);
							else
								JOptionPane.showMessageDialog(null, "没有你要修改的数据!",
										"系统提示!", JOptionPane.WARNING_MESSAGE);
							Select();
							
							stm.close();
							con.close();
							
							}catch(Exception e1){
								
							}
					} else {
					}
				} catch (Exception e1) {
				}
			}
		});
		button_2.setText("修改");
		button_2.setBounds(306, 370, 63, 28);
		getContentPane().add(button_2);

		final JLabel label_4 = new JLabel();
		final TitledBorder titledBorder_1 = new TitledBorder(null, "录入考试成绩",
				TitledBorder.DEFAULT_JUSTIFICATION,
				TitledBorder.DEFAULT_POSITION, null, null);
		titledBorder_1.setTitleFont(new Font("宋体", Font.PLAIN, 15));
		final TitledBorder titledBorder_2 = new TitledBorder(null, "录入考试成绩",
				TitledBorder.DEFAULT_JUSTIFICATION,
				TitledBorder.DEFAULT_POSITION, null, null);
		titledBorder_2.setTitleFont(new Font("", Font.PLAIN, 15));
		label_4.setBorder(titledBorder_2);
		label_4.setBounds(10, 242, 627, 178);
		getContentPane().add(label_4);

		label_5 = new JLabel();
		label_5.setFont(new Font("", Font.PLAIN, 14));
		label_5.setBounds(506, 375, 131, 18);
		getContentPane().add(label_5);

		final JButton button_3 = new JButton();
		button_3.setFont(new Font("", Font.PLAIN, 14));
		button_3.addActionListener(new ActionListener() {
			public void actionPerformed(final ActionEvent e) {
				Select();
			}
		});
		button_3.setText("查询");
		button_3.setBounds(481, 19, 63, 28);
		getContentPane().add(button_3);

		final JButton button_4 = new JButton();
		button_4.setFont(new Font("", Font.PLAIN, 14));
		button_4.addActionListener(new ActionListener() {
			public void actionPerformed(final ActionEvent e) {
				dispose();
			}
		});
		button_4.setText("退出");
		button_4.setBounds(574, 19, 63, 28);
		getContentPane().add(button_4);

		final JButton button_5 = new JButton();
		button_5.setFont(new Font("", Font.PLAIN, 14));
		button_5.addActionListener(new ActionListener() {
			public void actionPerformed(final ActionEvent e) {
				Select();
				textField_1.setText("");
				textField_2.setText("");
			}
		});
		button_5.setText("刷新");
		button_5.setBounds(113, 370, 63, 28);
		getContentPane().add(button_5);

		final JButton button_6 = new JButton();
		button_6.setFont(new Font("", Font.PLAIN, 14));
		button_6.addActionListener(new ActionListener() {
			public void actionPerformed(final ActionEvent e) {

				String sql = "delete   from 成绩表  where 学号='"
						+ textField_1.getText().trim() + "' and 课程名='"
						+ comboBox_1.getSelectedItem() + "'";
				// System.out.println(sql);
				try {
					int result = JOptionPane.showOptionDialog(null,
							"是否对数据进行删除?", "系统提示", JOptionPane.YES_NO_OPTION,
							JOptionPane.QUESTION_MESSAGE, null, new String[] {
									"是", "否" }, "否");
					if (result == JOptionPane.OK_OPTION) {
						
						try{
						Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
						Connection con = DriverManager
								.getConnection("jdbc:odbc:DB_Student");
						Statement stm = con.createStatement();
						
						if (stm.executeUpdate(sql) != 0)
							JOptionPane.showMessageDialog(null, "数据删除成功!",
									"系统提示!", JOptionPane.INFORMATION_MESSAGE);
						else
							JOptionPane.showMessageDialog(null, "没有你要删除的数据!",
									"系统提示!", JOptionPane.WARNING_MESSAGE);
						Select();
						
						stm.close();
						con.close();
						
						}catch(Exception e1){
							
						}
					} else {
					}
				} catch (Exception e3) {
				}
			}
		});
		button_6.setText("删除");
		button_6.setBounds(404, 370, 63, 28);
		getContentPane().add(button_6);

		final JButton button_7 = new JButton();
		button_7.setFont(new Font("", Font.PLAIN, 14));
		button_7.addActionListener(new ActionListener() {
			public void actionPerformed(final ActionEvent e) {

				try {
					String str;
					FileReader input = new FileReader(textField.getText());
					BufferedReader output = new BufferedReader(input);
					while ((str = output.readLine()) != null) {
						//System.out.println(str);
						Pattern p = Pattern.compile("\\d+(\\.\\d+)?");
				
						Matcher m = p.matcher(str);
						String two[] = new String[2];
						int i = 0;
						while (m.find()) {
							String val = m.group();
							//System.out.println(val);
							two[i++] = val;
							if(i==2)break;
						}

						String sql2 = " select 学号 from 学生表,授课关系表 where 学生表.学号='"
								+ two[0]
								+ "' and 学生表.班级名='"
								+ comboBox.getSelectedItem()
								+ "' and 课程名='"
								+ comboBox_1.getSelectedItem()
								+ "' and 学生表.班级名=授课关系表.班级名";

						boolean flag = false;
						try {
							Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
							Connection con = DriverManager
									.getConnection("jdbc:odbc:DB_Student");
							Statement stm = con.createStatement();
							if (stm.execute(sql2)) {
								flag = true;
							}
						} catch (Exception e2) {
							// e2.printStackTrace();
						}
						// System.out.println(flag);
						if (flag) {
							String sql = "insert  into  成绩表(学号,课程名,考试成绩)  values('"
									+ two[0]
									+ "','"
									+ comboBox_1.getSelectedItem()
									+ "','"
									+ two[1] + "')";

							// System.out.println(sql);
							try {
								new getResults().Results(sql);
							} catch (Exception e1) {
							}
							
						}

					}
					JOptionPane.showMessageDialog(null, "数据成功导入!!!", "系统提示",
							JOptionPane.INFORMATION_MESSAGE);
					
					Select();

				} catch (IOException e1) {

					// e1.printStackTrace();
				}
			}
		});
		button_7.setText("确定");
		button_7.setBounds(404, 321, 63, 28);
		getContentPane().add(button_7);
	}

	public void Select() {

		String sql = "select 学生表.学号,姓名,考试成绩 from 学生表,成绩表 where 班级名='"
				+ comboBox.getSelectedItem() + "' and 课程名='"
				+ comboBox_1.getSelectedItem() + "'and 学生表.学号=成绩表.学号";
		//System.out.println(sql);
		TableModel tableModel;
		try {
			tableModel = new getResults().Results(sql);
			table = new JTable(tableModel);
			scrollPane.setViewportView(table);
			table.setSelectionForeground(Color.RED);

			table.addMouseListener(new MouseAdapter() {

				public void mouseClicked(MouseEvent e) {
					int currow = table.getSelectedRow();
					textField_1.setText((String) table.getValueAt(currow, 0));
					textField_2.setText((table.getValueAt(currow, 2))
							.toString());
				}
			});
		} catch (Exception e3) {
			// e3.printStackTrace();
		}
	
		label_5.setText("共有: " + table.getRowCount() + " 条记录");
		if(table.getRowCount()==0)
			JOptionPane.showMessageDialog(null, "没有成绩记录","系统提示",JOptionPane.INFORMATION_MESSAGE);
		
	}
}

⌨️ 快捷键说明

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