4.25

地铁系统2:

package Data;

public class route {
    String name;
    String site;
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getSite() {
        return site;
    }
    public void setSite(String site) {
        this.site = site;
    }
    
    
    

}
package Data;

public class site {
    
    String name;
    String route;
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getRoute() {
        return route;
    }
    public void setRoute(String route) {
        this.route = route;
    }

    
    
}
package DBUtil;

import java.sql.Connection;

import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class DBUtil {
    public static Connection getConnection() throws ClassNotFoundException, SQLException {    
        Connection connection = null;
        Statement stmt = null;
        ResultSet rs = null;
     Class.forName("com.mysql.cj.jdbc.Driver");
      connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/subway", "root", "");   
 return connection;
 }
 public static void close(Connection connection ) {
      try {
        if (connection != null) {
             connection.close();
          }
        
     } catch (SQLException e) {
         e.printStackTrace();
    }
  }
  public static void close(PreparedStatement preparedStatement ) {
      try {
         if (preparedStatement != null) {
              preparedStatement.close();
          }            
     } catch (SQLException e) {
          e.printStackTrace();
      }
  }
  public static void close(ResultSet resultSet ) {
     try {
         if (resultSet != null) {
              resultSet.close();
          }
          
      } catch (SQLException e) {
          e.printStackTrace();
      }
  }
    

}

 

posted @ 2022-04-25 23:03  _Pi  阅读(80)  评论(0)    收藏  举报