结组作业第二天
内容:
package com.example.subway.database;
import java.sql.*;
public class DB {
public Connection conn = null;
public Statement stmt = null;
public ResultSet rs = null;
String url = "jdbc:mysql://172.18.151.86:3306/subway?useSSL=false&serverTimezone=UTC&allowPublicKeyRetrieval=true";
String username = "root";
String password = "123456";
public DB(){
try{
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection(url,username,password);
stmt = conn.createStatement();
}catch(SQLException se){
// 处理 JDBC 错误
se.printStackTrace();
}catch(Exception e){
// 处理 Class.forName 错误
e.printStackTrace();
}
}
public void close(){
try {
if (rs!=null){
rs.close();
}
if (stmt!=null){
stmt.close();
}
if (conn!=null){
conn.close();
}
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步