地铁查询系统3 实现了起点到终点查询的一半功能

我们团队截止到目前已经能够计算起始点到终点站的站数,与老师的要求还有一定的差距,我们会尽力赶上进度

chanxun-04.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="java.sql.*"%>
<jsp:useBean id="dao" class="DAO.dao"></jsp:useBean>
<jsp:useBean id="dbutil" class="DBUTIL.dbutil"></jsp:useBean>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h1> 起点与终点途径站点</h1>

<body>
<body>
<table border="1" align="center">
<tr>
<th>1.经历站点个数</th>
<th>2.地铁站名</th>

</tr>
<%
//计算输入的起点与终点之间的站点数
String station1=request.getParameter("station1");
String station2=request.getParameter("station2");
Connection connection = dbutil.getConnection();
int stationid1= dao.getstationid(station1);
int stationid2 = dao.getstationid(station2);
int stationid3 = stationid1-stationid2;
if(stationid3 < 0 )
stationid3 *= -1;
request.setAttribute("stationid3",stationid3);


%>
<tr>
<td>中间的站点数:${stationid3}</td>


</table>

</body>
</html>

 

dao层代码

package DAO;
import java.beans.Beans;
import java.sql.Connection;
import java.sql.JDBCType;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.mysql.cj.xdevapi.Statement;
import BEAN.bean;
import DBUTIL.dbutil;
public class dao {
//通过站名找到站点号

private static int getstationid = 0;

public int getstationid(String station) throws Exception{
Connection connection=null;
PreparedStatement preparedStatement=null;
ResultSet resultSet=null;
try {
connection= dbutil.getConnection();
String sql="select stationid from underground where station=?";
preparedStatement=connection.prepareStatement(sql);
preparedStatement.setString(1,station);
resultSet = preparedStatement.executeQuery();
while (resultSet.next()){

getstationid=resultSet.getInt("stationid");

}
} catch (SQLException e) {
e.printStackTrace();
}finally {
dbutil.close(resultSet,preparedStatement,connection);
}
return getstationid;

}
}

 

 

posted @ 2023-03-20 20:10  搜一码赛  阅读(50)  评论(0编辑  收藏  举报