📄 updatestudentaction.java
字号:
package edu.xscj.action;
import java.sql.Connection;
import edu.xscj.conn.ConnectDataBase;
import edu.xscj.bean.Student;
import java.sql.PreparedStatement;
public class UpdateStudentAction {
Connection conn = null;
public UpdateStudentAction() {
if (conn == null) {
conn = ConnectDataBase.getConn();
}
}
public void setConn() {
if (conn == null) {
conn = ConnectDataBase.getConn();
}
}
public String updateStudent(Student student) {
PreparedStatement pstmt = null;
String str = "";
try {
if (conn == null) {
this.setConn();
}
pstmt = conn.prepareStatement(
"update student set stuName=?,stuSex=?,stuBirthday=? where stuNo=?");
pstmt.setString(1, student.getStuName());
pstmt.setString(2, student.getStuSex());
pstmt.setDate(3, student.getStuBirthday());
pstmt.setString(4, student.getStuNo());
pstmt.execute();
str = "sucess";
} catch (Exception ex) {
ex.printStackTrace();
str = "failer";
} finally {
try {
if (pstmt != null) {
pstmt.close();
}
if (conn != null) {
conn.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
return str;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -