结对作业(地铁查询项目)01

结对作业的第一天,我们做了开发计划,准备先从后端入手,构建项目
package Bean;
import java.sql.*;
public class DBBean {
private String driverStr = "com.mysql.jdbc.Driver";
private String connStr = "jdbc:mysql://localhost:3306/user";
private String dbusername = "root";
private String dbpassword = "20223959";
private Connection conn = null;
private Statement stmt = null;

public DBBean() {
try {
Class.forName(driverStr);
conn = DriverManager.getConnection(connStr, dbusername, dbpassword);
stmt = conn.createStatement();
} catch (Exception ex) {
System.out.println(ex.getMessage());
System.out.println("数据连接失败!");
}

}

public int executeUpdate(String s) {
int result = 0;
System.out.println("--更新语句:" + s + "\n");
try {
result = stmt.executeUpdate(s);
} catch (Exception ex) {
System.out.println("执行更新错误!");
}
return result;
}
public ResultSet executeQuery(String s) {
ResultSet rs = null;
System.out.print("--查询语句:" + s + "\n");
try {
rs = stmt.executeQuery(s);
} catch (Exception ex) {
System.out.println("执行查询错误!");
}
return rs;
}

public void execQuery(String s) {
try {
stmt.executeUpdate(s);
} catch (SQLException e) {

System.out.println("执行插入错误!");
}
}

public void close() {
try {
stmt.close();
conn.close();
} catch (Exception e) {
}
} }

posted @   平安喜乐×  阅读(4)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库
· SQL Server 2025 AI相关能力初探
· 为什么 退出登录 或 修改密码 无法使 token 失效
点击右上角即可分享
微信分享提示