赞
踩
如下代码供学习交流,获取完整代码,请关注文后二维码(coding加油站)回复“数据库学籍管理”免费获取
1、简介
可以用于数据库作业的设计,也可以用于javase作业的设计,数据库为sql server
功能说明:
2、项目截图
3、项目代码:
java代码:
- package database;
-
- import java.awt.Component;
- import java.awt.event.MouseAdapter;
- import java.awt.event.MouseEvent;
-
- import javax.swing.JCheckBox;
- import javax.swing.JComponent;
- import javax.swing.JLabel;
- import javax.swing.JTable;
- import javax.swing.SwingConstants;
- import javax.swing.UIManager;
- import javax.swing.table.JTableHeader;
- import javax.swing.table.TableCellRenderer;
-
- public class CheckHeaderCellRenderer implements TableCellRenderer {
- CheckTableModle tableModel;
- JTableHeader tableHeader;
- final JCheckBox selectBox;
-
- public CheckHeaderCellRenderer(JTable table) {
- this.tableModel = (CheckTableModle)table.getModel();
- this.tableHeader = table.getTableHeader();
- selectBox = new JCheckBox(tableModel.getColumnName(0));
- selectBox.setSelected(false);
- tableHeader.addMouseListener(new MouseAdapter() {
- public void mouseClicked(MouseEvent e) {
- if (e.getClickCount() > 0) {
- //获得选中列
- int selectColumn = tableHeader.columnAtPoint(e.getPoint());
- if (selectColumn == 0) {
- boolean value = !selectBox.isSelected();
- selectBox.setSelected(value);
- tableModel.selectAllOrNull(value);
- tableHeader.repaint();
- }
- }
- }
- });
- }
- @Override
- public Component getTableCellRendererComponent(JTable table, Object value,
- boolean isSelected, boolean hasFocus, int row, int column) {
- // TODO Auto-generated method stub
- String valueStr = (String) value;
- JLabel label = new JLabel(valueStr);
- label.setHorizontalAlignment(SwingConstants.CENTER); // 表头标签剧中
- selectBox.setHorizontalAlignment(SwingConstants.CENTER);// 表头标签剧中
- selectBox.setBorderPainted(true);
- JComponent component = (column == 0) ? selectBox : label;
-
- component.setForeground(tableHeader.getForeground());
- component.setBackground(tableHeader.getBackground());
- component.setFont(tableHeader.getFont());
- component.setBorder(UIManager.getBorder("TableHeader.cellBorder"));
-
- return component;
- }
-
- }
- package database;
-
- import java.awt.BorderLayout;
- import java.awt.EventQueue;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.util.Vector;
-
- import javax.swing.JButton;
- import javax.swing.JCheckBox;
- import javax.swing.JFileChooser;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JOptionPane;
- import javax.swing.JPanel;
- import javax.swing.JScrollPane;
- import javax.swing.JTable;
- import javax.swing.JTextField;
- import javax.swing.border.EmptyBorder;
- import javax.swing.filechooser.FileNameExtensionFilter;
- import javax.swing.table.DefaultTableModel;
- import javax.swing.table.TableColumn;
-
- public class Course_insert extends JFrame {
-
-
- private JPanel contentPane;
- private JTextField textField;
- private JTextField textField_1;
- private JCheckBox checkBox_2,checkBox_1,checkBox;
- private Vector<Integer> order=new Vector<Integer>();
- private final String[] name=new String[]{"课程号","课程名","学分","课程类型"};
- private JPanel panel;
- /**
- * Launch the application.
- */
- public static void main(String[] args) {
- EventQueue.invokeLater(new Runnable() {
- public void run() {
- try {
- Sql_connetcton.login_s("admin", "admin");
- Course_insert frame = new Course_insert();
- frame.setVisible(true);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
-
- /**
- * Create the frame.
- */
- public Course_insert() {
- setTitle("\u8BFE\u7A0B\u4FE1\u606F\u5BFC\u5165");
- setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
- setBounds(100, 100, 450, 300);
- contentPane = new JPanel();
- this.setResizable(false);//居中
- this.setLocationRelativeTo(null);
- contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
- setContentPane(contentPane);
- contentPane.setLayout(null);
- ActionListener checkBoxListener=new ActionListener() {
-
- @Override
- public void actionPerformed(ActionEvent e) {
- String s=textField_1.getText();
- if(((JCheckBox)e.getSource()).isSelected()){
- s+=e.getActionCommand()+",";
- }else{
- s=s.replaceAll(e.getActionCommand()+",","");
- }
- textField_1.setText(s);
- }
- };
-
- JLabel lblNewLabel = new JLabel("\u5BFC\u5165\u6587\u4EF6:");
- lblNewLabel.setBounds(10, 10, 63, 15);
- contentPane.add(lblNewLabel);
-
- textField = new JTextField();
- textField.setBounds(67, 7, 216, 21);
- contentPane.add(textField);
- textField.setColumns(10);
-
- JButton button = new JButton("...");
- button.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- JFileChooser file=new JFileChooser();
- file.setAcceptAllFileFilterUsed(false); //关闭所有文件筛选器
- file.setMultiSelectionEnabled(false); //关闭多选
- file.setFileFilter(new FileNameExtensionFilter("TXT", "txt")); //添加txt筛选器
- if(file.showDialog(getParent(), "导入")==JFileChooser.APPROVE_OPTION){
- textField.setText(file.getSelectedFile().getPath()); //获得保存路径
- }
-
- }
- });
- button.setBounds(287, 7, 25, 21);
- contentPane.add(button);
-
- JButton button_1 = new JButton("\u5BFC\u5165");
-
- button_1.setBounds(379, 6, 63, 23);
- contentPane.add(button_1);
-
- JButton button_2 = new JButton("\u9884\u89C8");
-
- button_2.setBounds(315, 6, 63, 23);
- contentPane.add(button_2);
-
- JLabel label = new JLabel("\u5BFC\u5165\u683C\u5F0F:");
- label.setBounds(10, 38, 87, 15);
- contentPane.add(label);
-
- textField_1 = new JTextField();
- textField_1.setBounds(67, 35, 216, 21);
- contentPane.add(textField_1);
- textField_1.setColumns(10);
- checkBox = new JCheckBox("\u8BFE\u7A0B\u53F7");
- checkBox.setBounds(10, 59, 63, 23);
- checkBox.addActionListener(checkBoxListener);
- checkBox.addActionListener(new ActionListener() {
-
- @Override
- public void actionPerformed(ActionEvent e) {
- if(((JCheckBox)e.getSource()).isSelected()){
- order.add(new Integer(0));
- }else{
- order.remove(new Integer(0));
- }
- }
- });
-
- checkBox_2 = new JCheckBox("\u5B66\u5206");
- checkBox_2.setBounds(146, 59, 54, 23);
- checkBox_2.addActionListener(checkBoxListener);
- checkBox_2.addActionListener(new ActionListener() {
-
- @Override
- public void actionPerformed(ActionEvent e) {
- if(((JCheckBox)e.getSource()).isSelected()){
- order.add(new Integer(2));
- }else{
- order.remove(new Integer(2));
- }
-
- }
- });
- contentPane.add(checkBox_2);
-
- checkBox_1 = new JCheckBox("\u8BFE\u7A0B\u540D");
- checkBox_1.setBounds(77, 59, 67, 23);
- checkBox_1.addActionListener(checkBoxListener);
- checkBox_1.addActionListener(new ActionListener() {
-
- @Override
- public void actionPerformed(ActionEvent e) {
- if(((JCheckBox)e.getSource()).isSelected()){
- order.add(new Integer(1));
- }else{
- order.remove(new Integer(1));
- }
-
- }
- });
- contentPane.add(checkBox_1);
- contentPane.add(checkBox);
- final JButton button_3 = new JButton("\u9501\u5B9A");
- button_3.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- String s=textField_1.getText();
- if(e.getActionCommand()=="锁定"){
- textField_1.setEnabled(false);
- checkBox_2.setEnabled(false);
- checkBox_1.setEnabled(false);
- checkBox.setEnabled(false);
- if(s.endsWith(",")){
- textField_1.setText(s.substring(0,s.length()-1));
- }
- button_3.setText("解锁");
- }else{
- textField_1.setEnabled(true);
- checkBox_2.setEnabled(true);
- checkBox_1.setEnabled(true);
- checkBox.setEnabled(true);
- textField_1.setText(s+",");
- button_3.setText("锁定");
- }
- }
- });
- button_3.setBounds(287, 34, 63, 23);
- contentPane.add(button_3);
- panel = new JPanel();
- panel.setBounds(10, 88, 424, 173);
- contentPane.add(panel);
- panel.setLayout(new BorderLayout(0, 0));//保持边距,不然会超出显示区域
- final JTable table = new JTable();
-
- panel.removeAll();
- JScrollPane sPane=new JScrollPane(table);
- sPane.setAutoscrolls(true);
- panel.add(sPane,BorderLayout.CENTER);
-
- JCheckBox kind = new JCheckBox("\u8BFE\u7A0B\u7C7B\u578B");
- kind.setBounds(202, 59, 103, 23);
- contentPane.add(kind);
- kind.addActionListener(new ActionListener() {
-
- @Override
- public void actionPerformed(ActionEvent e) {
- if(((JCheckBox)e.getSource()).isSelected()){
- order.add(new Integer(3));
- }else{
- order.remove(new Integer(3));
- }
-
- }
- });
- kind.addActionListener(checkBoxListener);
- button_2.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- final Vector<Vector<String>> ans=
- file_insert.get(textField_1.getText(), textField.getText(), name, order);
- //file_insert.get("","C:\\Users\\jxy1\\Documents\\GitHub\\Database-project\\导入数据\\test.txt",name,order);
- final Vector<String> names=new Vector<String>();
- for(String s:name)names.add(s);
- DefaultTableModel dataModel=new DefaultTableModel(ans,names)
- {
-
-
-
-
- @Override
- public boolean isCellEditable(int rowIndex, int columnIndex) {
-
- return false;
- }
-
- @Override
- public Object getValueAt(int rowIndex, int columnIndex) {
- if(columnIndex==0){
- return rowIndex+1;
- }
- Vector rowVector = (Vector)dataVector.elementAt(rowIndex);
- if(columnIndex==4)
- if(rowVector.elementAt(columnIndex-1)=="NULL")
- setValueAt("必修", rowIndex, columnIndex-1);
- return rowVector.elementAt(columnIndex-1);
- }
-
- @Override
- public String getColumnName(int columnIndex) {
- if(columnIndex==0)return "序号";
- return names.get(columnIndex-1);
- }
-
- @Override
- public int getColumnCount() {
- return names.size()+1;
- }
-
-
- };
-
- table.setModel(dataModel);
- for(int i=0;i<1;i++){
- TableColumn column = table.getColumnModel().getColumn(i);
- column.setPreferredWidth(25);
- }
-
-
- }
- });
- button_1.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
-
- DefaultTableModel now=(DefaultTableModel) table.getModel();
- int row=now.getRowCount(),col=now.getColumnCount()-1;
- int rr=0;
- Vector s= now.getDataVector();
- for(int i=0;i<row;i++){
- Vector<String> temp=(Vector<String>) s.elementAt(rr);
- if(temp.size()>col)temp.remove(col);
- if(Sql_connetcton.insert(temp,"课程")==true){
- now.removeRow(rr);
- }else{
- rr++;
- }
- }
-
- JOptionPane.showMessageDialog(null,"成功"+(row-rr)+"个,失败"+rr+"个","导入结果", JOptionPane.INFORMATION_MESSAGE);
-
- }
- });
-
- }
- }
数据库相关sql:
- USE [学籍管理系统]
- GO
-
- /****** Object: Table [dbo].[专业] Script Date: 12/18/2021 00:42:01 ******/
- SET ANSI_NULLS ON
- GO
-
- SET QUOTED_IDENTIFIER ON
- GO
-
- CREATE TABLE [dbo].[专业](
- [专业号] [int] NOT NULL,
- [专业名] [nchar](10) NOT NULL,
- [学院名] [nchar](10) NOT NULL,
- PRIMARY KEY CLUSTERED
- (
- [专业号] ASC
- )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
- ) ON [PRIMARY]
-
- GO
-
- USE [学籍管理系统]
- GO
-
- /****** Object: Table [dbo].[班级] Script Date: 12/18/2021 00:42:08 ******/
- SET ANSI_NULLS ON
- GO
-
- SET QUOTED_IDENTIFIER ON
- GO
-
- CREATE TABLE [dbo].[班级](
- [班号] [nchar](6) NOT NULL,
- [专业号] [int] NOT NULL,
- [班主任] [nchar](10) NOT NULL,
- [入学年份] [int] NOT NULL,
- CONSTRAINT [PK_班级] PRIMARY KEY CLUSTERED
- (
- [班号] ASC
- )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
- ) ON [PRIMARY]
-
- GO
-
- ALTER TABLE [dbo].[班级] WITH CHECK ADD CONSTRAINT [FK_班级_专业] FOREIGN KEY([专业号])
- REFERENCES [dbo].[专业] ([专业号])
- GO
-
- ALTER TABLE [dbo].[班级] CHECK CONSTRAINT [FK_班级_专业]
- GO
-
- ALTER TABLE [dbo].[班级] WITH CHECK ADD CONSTRAINT [CK_班级] CHECK (([入学年份]>(1800) AND [入学年份]<(10000)))
- GO
-
- ALTER TABLE [dbo].[班级] CHECK CONSTRAINT [CK_班级]
- GO
-
- USE [学籍管理系统]
- GO
-
- /****** Object: Table [dbo].[学生] Script Date: 12/18/2021 00:42:18 ******/
- SET ANSI_NULLS ON
- GO
-
- SET QUOTED_IDENTIFIER ON
- GO
-
- CREATE TABLE [dbo].[学生](
- [班号] [nchar](6) NULL,
- [学号] [nchar](8) NOT NULL,
- [姓名] [nchar](10) NOT NULL,
- [性别] [nchar](1) NOT NULL,
- [出生日期] [smalldatetime] NULL,
- CONSTRAINT [PK_学生] PRIMARY KEY CLUSTERED
- (
- [学号] ASC
- )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
- ) ON [PRIMARY]
-
- GO
-
- ALTER TABLE [dbo].[学生] WITH CHECK ADD CONSTRAINT [FK_学生_班级] FOREIGN KEY([班号])
- REFERENCES [dbo].[班级] ([班号])
- GO
-
- ALTER TABLE [dbo].[学生] CHECK CONSTRAINT [FK_学生_班级]
- GO
-
- ALTER TABLE [dbo].[学生] WITH CHECK ADD CONSTRAINT [CK_学生] CHECK (([性别]=N'女' OR [性别]=N'男'))
- GO
-
- ALTER TABLE [dbo].[学生] CHECK CONSTRAINT [CK_学生]
- GO
-
- ALTER TABLE [dbo].[学生] ADD CONSTRAINT [DF_学生_性别] DEFAULT (N'男') FOR [性别]
- GO
-
- USE [学籍管理系统]
- GO
-
- /****** Object: Table [dbo].[课程] Script Date: 12/18/2021 00:42:25 ******/
- SET ANSI_NULLS ON
- GO
-
- SET QUOTED_IDENTIFIER ON
- GO
-
- CREATE TABLE [dbo].[课程](
- [课程号] [nchar](9) NOT NULL,
- [课程名] [nchar](25) NOT NULL,
- [学分] [int] NOT NULL,
- [课程类型] [nchar](2) NOT NULL,
- CONSTRAINT [PK_课程] PRIMARY KEY CLUSTERED
- (
- [课程号] ASC
- )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
- ) ON [PRIMARY]
-
- GO
-
- ALTER TABLE [dbo].[课程] WITH CHECK ADD CONSTRAINT [CK_课程] CHECK (([课程类型]='任选' OR [课程类型]='限选' OR [课程类型]='必修'))
- GO
-
- ALTER TABLE [dbo].[课程] CHECK CONSTRAINT [CK_课程]
- GO
-
- ALTER TABLE [dbo].[课程] ADD CONSTRAINT [DF_课程_课程类型] DEFAULT (N'必修') FOR [课程类型]
- GO
-
- USE [学籍管理系统]
- GO
-
- /****** Object: Table [dbo].[课表] Script Date: 12/18/2021 00:42:30 ******/
- SET ANSI_NULLS ON
- GO
-
- SET QUOTED_IDENTIFIER ON
- GO
-
- CREATE TABLE [dbo].[课表](
- [课程号] [nchar](9) NOT NULL,
- [班级号] [nchar](6) NOT NULL,
- [任课教师] [nchar](10) NOT NULL,
- CONSTRAINT [PK_课表] PRIMARY KEY CLUSTERED
- (
- [任课教师] ASC,
- [班级号] ASC
- )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
- ) ON [PRIMARY]
-
- GO
-
- ALTER TABLE [dbo].[课表] WITH CHECK ADD CONSTRAINT [FK_课表_班级] FOREIGN KEY([班级号])
- REFERENCES [dbo].[班级] ([班号])
- GO
-
- ALTER TABLE [dbo].[课表] CHECK CONSTRAINT [FK_课表_班级]
- GO
-
- ALTER TABLE [dbo].[课表] WITH CHECK ADD CONSTRAINT [FK_课表_课程] FOREIGN KEY([课程号])
- REFERENCES [dbo].[课程] ([课程号])
- GO
-
- ALTER TABLE [dbo].[课表] CHECK CONSTRAINT [FK_课表_课程]
- GO
-
- USE [学籍管理系统]
- GO
-
- /****** Object: Table [dbo].[教学计划] Script Date: 12/18/2021 00:42:50 ******/
- SET ANSI_NULLS ON
- GO
-
- SET QUOTED_IDENTIFIER ON
- GO
-
- CREATE TABLE [dbo].[教学计划](
- [学期] [nchar](1) NOT NULL,
- [专业号] [int] NOT NULL,
- [课程号] [nchar](9) NOT NULL,
- CONSTRAINT [PK_教学计划] PRIMARY KEY CLUSTERED
- (
- [专业号] ASC,
- [课程号] ASC
- )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
- ) ON [PRIMARY]
-
- GO
-
- ALTER TABLE [dbo].[教学计划] WITH CHECK ADD CONSTRAINT [FK_教学计划_课程] FOREIGN KEY([课程号])
- REFERENCES [dbo].[课程] ([课程号])
- GO
-
- ALTER TABLE [dbo].[教学计划] CHECK CONSTRAINT [FK_教学计划_课程]
- GO
-
- ALTER TABLE [dbo].[教学计划] WITH CHECK ADD CONSTRAINT [FK_教学计划_专业] FOREIGN KEY([专业号])
- REFERENCES [dbo].[专业] ([专业号])
- GO
-
- ALTER TABLE [dbo].[教学计划] CHECK CONSTRAINT [FK_教学计划_专业]
- GO
-
- ALTER TABLE [dbo].[教学计划] WITH CHECK ADD CONSTRAINT [CK_教学计划] CHECK (([学期]>(0) AND [学期]<(9)))
- GO
-
- ALTER TABLE [dbo].[教学计划] CHECK CONSTRAINT [CK_教学计划]
- GO
-
- USE [学籍管理系统]
- GO
-
- /****** Object: Table [dbo].[成绩] Script Date: 12/18/2021 00:42:53 ******/
- SET ANSI_NULLS ON
- GO
-
- SET QUOTED_IDENTIFIER ON
- GO
-
- CREATE TABLE [dbo].[成绩](
- [学号] [nchar](8) NOT NULL,
- [课程号] [nchar](9) NOT NULL,
- [成绩] [int] NULL,
- [补考成绩] [int] NULL,
- [真实成绩] [int] NULL,
- CONSTRAINT [PK_成绩] PRIMARY KEY CLUSTERED
- (
- [学号] ASC,
- [课程号] ASC
- )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
- ) ON [PRIMARY]
-
- GO
-
- ALTER TABLE [dbo].[成绩] WITH CHECK ADD CONSTRAINT [FK_成绩_课程] FOREIGN KEY([课程号])
- REFERENCES [dbo].[课程] ([课程号])
- GO
-
- ALTER TABLE [dbo].[成绩] CHECK CONSTRAINT [FK_成绩_课程]
- GO
-
- ALTER TABLE [dbo].[成绩] WITH CHECK ADD CONSTRAINT [FK_成绩_学生] FOREIGN KEY([学号])
- REFERENCES [dbo].[学生] ([学号])
- GO
-
- ALTER TABLE [dbo].[成绩] CHECK CONSTRAINT [FK_成绩_学生]
- GO
-
- ALTER TABLE [dbo].[成绩] WITH CHECK ADD CONSTRAINT [CK_成绩] CHECK (([成绩]>=(0) AND [成绩]<=(100)))
- GO
-
- ALTER TABLE [dbo].[成绩] CHECK CONSTRAINT [CK_成绩]
- GO
-
- ALTER TABLE [dbo].[成绩] WITH CHECK ADD CONSTRAINT [CK_成绩_t] CHECK (([补考成绩] IS NULL OR [成绩] IS NOT NULL AND [补考成绩]>=(0) AND [补考成绩]<=(100) AND [成绩]<(60)))
- GO
-
- ALTER TABLE [dbo].[成绩] CHECK CONSTRAINT [CK_成绩_t]
- GO
-
如下代码供学习交流,获取完整代码,请关注文后二维码(coding加油站)回复“数据库学籍管理”免费获取
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。