4.3

连接数据库

public class DB {
public Connection conn = null;
public Statement stmt = null;
public ResultSet rs = null;
String url = "jdbc:mysql://localhost:3306/subway?useSSL=false&serverTimezone=UTC";
String username = "root";
String password = "a123456";
public DB(){
try{
Class.forName("com.mysql.cj.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);
}
}


}
public class SubwayBean {

public String _StartStation;
public String _EndStation;
public Object _Number;
public String _Path;
}
页面太复杂,还没有完成
posted @ 2024-04-19 22:51  涨涨涨张  阅读(3)  评论(0编辑  收藏  举报