首页 > 其他分享 >地铁查询系统3 实现了起点到终点查询的一半功能

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

时间:2023-03-20 20:24:55浏览次数:31  
标签:getstationid 终点 java stationid3 resultSet 查询 地铁 sql import

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

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;

}
}

 

 

标签:getstationid,终点,java,stationid3,resultSet,查询,地铁,sql,import
From: https://www.cnblogs.com/jizhaosai/p/17237581.html

相关文章

  • 软件工程日报——SQL语句查询不能应用在jsp文件
    今天上课我们在课堂上讲解了如何搞对象,然后再后两节课我和我的伙伴进行了对地铁系统中初始站台和终点站台查询功能的研究。在这个过程中,我们发现一个问题:能够实现web页面查......
  • 北京地铁查询系统web端
      今天展示环节未展示,原因如下:  功能实现不全面,在网上找的模板是基于java文件输入输出运行的,在改成web端的过程中出现了很多问题。致使后面的工作进度与上周每日......
  • 尚硅谷MyBatis8_各种查询功能
    查询一个实体类对象查询出的数据只有一条,可以通过「实体类对象」or「集合」or「map」接收/***根据用户id查询用户信息*@paramid*@return*/UsergetUserById(@Pa......
  • PostgreSQL的递归查询(with recursive)
    [color=red][b]示例[/b][/color]withRECURSIVEcteas(selecta.*fromtb_sm_moduleawheremodule_id=0unionallselectk.*fromtb_sm_mod......
  • redis存储session如何查询当前请求的sessionID
    redis存储session如何查询当前请求的sessionID问题项目登录信息session使用的redis存储,在排查bug过程中需要查询缓存;发现无法知道,当前的浏览器请求获取到的缓存信息;解......
  • 为什么今日未上台演示地铁程序?
    我们小组实力有限,在建民老师课上时,我们还未完成该完成的基础的功能。以下是我们组在课上实现的功能展示:原因:可见,我们的第三个功能:起点——终点查询还未完成,所以,我们......
  • Medoo distinct count 统计查询写法
    Medoo写法://下面是meedo写法$data=$this->mysql->get('member_coupon_provide',['count_order'=>Medoo::raw('COUNT(DISTINCT(<orderNo>))'),],['sid......
  • 8.1.6mysql的条件子查询
    如题。一个不算复杂的东西,书上说的太绕了,不能忍。准备数据,这里有三张表(偷懒,各种编号都是整数)。t1是学生基本情况表,重要的字段是学号和姓名。t2是课程表,包括课程号和课程......
  • Oracle查询所有表怎样做,有几种方法 select * from user_tables 查询当前登录用用户
    Oracle查询所有表怎样做,有几种方法原文连接:https://www.qycn.com/xzx/article/13062.html在实际案例的操作过程中,我们可能会遇到“Oracle......
  • 小程序云开发联表查询
    我现在有两个集合要联查一个是类别(category),一个是地点(site)一个类别下有很多个地点那如果我要查出某个类别下有哪些类别怎么办?联表查询官方文档官方给出的方法是聚合查......