addstudentaction.java~16~

来自「java(Swing) access做的成绩管理系统」· JAVA~16~ 代码 · 共 45 行

JAVA~16~
45
字号
package edu.xscj.action;

import java.sql.Connection;
import edu.xscj.conn.ConnectDataBase;
import edu.xscj.bean.Student;
import java.sql.*;

public class AddStudentAction {
    Connection conn = null;

    public AddStudentAction() {
        if (conn == null) {
            conn = ConnectDataBase.getConn();
        }
    }

    public String addStudent(Student student){
        PreparedStatement pstmt = null;
        String str="";
        try {
            pstmt=conn.prepareStatement("insert into student values(?,?,?,?)");
            pstmt.setString(1,student.getStuNo());
            pstmt.setString(2,student.getStuName());
            pstmt.setString(3,student.getStuSex());
            pstmt.setDate(4,student.getStuBirthday());
            pstmt.execute();
            str="sucess";
        } catch (Exception ex) {

        } finally {
            try {
                                if (pstmt != null) {
                                        pstmt.close();
                                }
                                if (conn != null) {
                                        conn.close();
                                }
                        } catch (Exception e) {
                                e.printStackTrace();
                        }

        }
    }
}

⌨️ 快捷键说明

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