


package Dao;
import java.sql.*;
//工具类方便使用调用
public class DButil {
static Connection conn = null;
static Statement stat = null;
static PreparedStatement pstm = null;
static ResultSet rs = null;
public static String FileName = "src/jdbc";
public static String url;
public static String drive;
public static String name;
public static String password;
//增删该 通用方法
public static int executeUpdate(String sql, Object... params) {
int rows = 0;
try {
conn = getConnection();// 调用加载驱动
pstm = conn.prepareStatement(sql);
for (int i = 0; i < params.length; i++) {
pstm.setObject(i + 1, params[i]);
}
rows = pstm.executeUpdate();
} catch (Exception e) {
e.printStackTrace();
} finally {
closeALL(rs, stat, conn);
}
return rows;
}
//加载驱动方法(我用的是Oracle数据库)
public static Connection getConnection() throws SQLException {
try {
String url = "jdbc:oracle:thin:@127.0.0.1:1521:orcl";
String drive = "oracle.jdbc.driver.OracleDriver";
String name ="scott";
String password = "tiger";
Class.forName(drive);
conn = DriverManager.getConnection(url, name, password);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
return conn;
}
//关闭的所有方法
public static void closeALL(ResultSet rs, Statement stat, Connection conn) {
try {
if (rs != null) {
rs.close();
}
if (stat != null) {
stat.close();
}
if (conn != null) {
conn.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
package entity;
//实体类用于封装传输数据
public class Teacher {
private int id;
private String name;
private String sex;
private String address;
public int getId() {
return id;
}
public String getName() {
return name;
}
public String getSex() {
return sex;
}
public String getAddress() {
return address;
}
public void setId(int id) {
this.id = id;
}
public void setName(String name

本文主要介绍了前端页面的增删改功能实现,包括登录页面、删除操作、更新逻辑以及数据提交和添加。在删除页面中,通过获取ID调用接口实现删除;更新操作涉及查询和更新两个步骤;提交更新在genxin.jsp中完成;添加数据则在add.jsp和tianjia.jsp中处理。

1748

被折叠的 条评论
为什么被折叠?



