结对作业(地铁项目)02

后端2

package User;

import java.sql.*;

public class subway {
private String station_id, line_name, station_name, next_station,direction;

public String getStation_id() {
return station_id;
}

public void setStation_id(String station_id) {
this.station_id = station_id;
}

public String getLine_name() {
return line_name;
}

public void setLine_name(String line_name) {
this.line_name = line_name;
}

public String getStation_name() {
return station_name;
}

public void setStation_name(String station_name) {
this.station_name = station_name;
}

public String getNext_station() {
return next_station;
}

public void setNext_station(String next_station) {
this.next_station = next_station;
}

public String getDirection() {
return direction;
}

public void setDirection(String direction) {
this.direction = direction;
}

public Connection getConnection()//连接数据库
{
try {
Class.forName("com.mysql.jdbc.Driver");
System.out.println("加载驱动成功");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
String user = "root";
String password = "123456";
String url = "jdbc:mysql://localhost:3306/user?characterEncoding=utf8&useSSL=false&serverTimezone=UTC&rewriteBatchedStatements=true";
Connection con = null;
try {
con = DriverManager.getConnection(url, user, password);
System.out.println("数据库连接成功");
} catch (SQLException e) {
e.printStackTrace();
}
return con;
}

//**********************************************************************
//关闭方法
public void close(Connection con) {
try {
if (con != null) {
con.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
}

public void close(PreparedStatement preparedStatement) {
try {
if (preparedStatement != null) {
preparedStatement.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
}

public void close(ResultSet resultSet) {
try {
if (resultSet != null) {
resultSet.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
}

public void select(String station_id, String line_name, String station_name,String next_station,String direction) {
Connection connection = getConnection();
PreparedStatement preparedStatement = null;
try {
String sql = "select * from bj_subway";
preparedStatement = connection.prepareStatement(sql);
preparedStatement.executeUpdate();

} catch (SQLException e) {
e.printStackTrace();
} finally {
close(preparedStatement);
close(connection);
}

}

public static void main(String[] args)
{
//Data a=new Data();
}

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