每周总结之第六周
2022/6/14 23:22:06
本文主要是介绍每周总结之第六周,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
这周进行的课堂测试是地铁信息系统,我完成了第一阶段,实现了站点查询,线路查询,起点——终点查询可以查看,代码部分如
package Dao;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import Dao.DBUtil;
import Javabean.bean;
public class Dao {
public Dao() {
// TODO Auto-generated constructor stub
}
public static bean searchxianlu(String xianlu)
{
Connection conn = DBUtil.getConn();
Statement state = null;
ResultSet rs = null;
String teaname=null;
bean be=new bean();
try {
String sql="select zhanming from jiben where xianluhao= '"+xianlu+"'";
state = conn.createStatement();
System.out.print(xianlu+"号线:");
rs = state.executeQuery(sql);
while(rs.next()){
teaname = rs.getString("zhanming");
System.out.print(teaname+' ');
be.setZhanming(rs.getString("zhanming"));
}
System.out.println(be.getZhanming());
}
catch(SQLException e) {
e.printStackTrace();
}
finally {
DBUtil.close(state, conn);
}
return be;
}
public static String searchzhandian(String zhanming)
{
Connection conn = DBUtil.getConn();
Statement state = null;
ResultSet rs = null;
String teaname=null;
bean bean=new bean();
try {
String sql="select xianluhao from jiben where zhanming= '"+zhanming+"'";
state = conn.createStatement();
System.out.print(zhanming+":该站途径 ");
rs = state.executeQuery(sql);
while(rs.next()){
teaname = rs.getString("xianluhao");
System.out.print(teaname+"号线 ");
bean.setXianluhao(teaname);
}
}
catch(SQLException e) {
e.printStackTrace();
}
finally {
DBUtil.close(state, conn);
}
return teaname;
}
public List<bean> getallxianluhao(String xianluhao){
Connection conn = DBUtil.getConn();
List<bean> list=new ArrayList<bean>();
try {String sql="select zhanming from jiben where xianluhao= '"+xianluhao+"'";
Statement state = null;
ResultSet rs = null;
ResultSet ps = null;
state = conn.createStatement();
rs = state.executeQuery(sql);
while (rs.next()) {
bean bean=new bean();
bean.setZhanming(rs.getString("zhanming"));
list.add(bean);
}
} catch (SQLException e) {
e.printStackTrace();
}
return list;
}
public List<bean> getallzhanming(String zhanming){
Connection conn = DBUtil.getConn();
List<bean> list=new ArrayList<bean>();
try {String sql="select xianluhao from jiben where zhanming= '"+zhanming+"'";
Statement state = null;
ResultSet rs = null;
ResultSet ps = null;
state = conn.createStatement();
rs = state.executeQuery(sql);
while (rs.next()) {
bean bean=new bean();
bean.setXianluhao(rs.getString("xianluhao"));
list.add(bean);
}
} catch (SQLException e) {
e.printStackTrace();
}
return list;
}
public static int searchqidian( String qidian)
{
Connection conn = DBUtil.getConn();
Statement state = null;
ResultSet rs = null;
int teaname=-1;
try {
String sql="select chezhanid from jiben where zhanming= '"+qidian+"'";
state = conn.createStatement();
rs = state.executeQuery(sql);
while(rs.next()){
teaname = rs.getInt("chezhanid");
System.out.print(teaname);
}
}
catch(SQLException e) {
e.printStackTrace();
}
finally {
DBUtil.close(state, conn);
}
return teaname;
}
public static int searchzhongdian(String zhongdian)
{
Connection conn = DBUtil.getConn();
Statement state = null;
ResultSet rs = null;
int teaname=-1;
try {
String sql="select chezhanid from jiben where zhanming= '"+zhongdian+"'";
state = conn.createStatement();
rs = state.executeQuery(sql);
while(rs.next()){
teaname = rs.getInt("chezhanid");
System.out.print(teaname);
}
}
catch(SQLException e) {
e.printStackTrace();
}
finally {
DBUtil.close(state, conn);
}
return teaname;
}
public List<bean> getallqishi(int qi,int zhong,String xianluhao){
Connection conn = DBUtil.getConn();
List<bean> list=new ArrayList<bean>();
try {String sql="select zhanming from jiben where chezhanid<='"+zhong+"'and chezhanid>='"+qi+"'and xianluhao ='"+xianluhao+"'";
Statement state = null;
ResultSet rs = null;
ResultSet ps = null;
state = conn.createStatement();
rs = state.executeQuery(sql);
while (rs.next()) {
bean bean=new bean();
bean.setZhanming(rs.getString("zhanming"));
list.add(bean);
}
} catch (SQLException e) {
e.printStackTrace();
}
return list;
}
}
这篇关于每周总结之第六周的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-23Springboot应用的多环境打包入门
- 2024-11-23Springboot应用的生产发布入门教程
- 2024-11-23Python编程入门指南
- 2024-11-23Java创业入门:从零开始的编程之旅
- 2024-11-23Java创业入门:新手必读的Java编程与创业指南
- 2024-11-23Java对接阿里云智能语音服务入门详解
- 2024-11-23Java对接阿里云智能语音服务入门教程
- 2024-11-23JAVA对接阿里云智能语音服务入门教程
- 2024-11-23Java副业入门:初学者的简单教程
- 2024-11-23JAVA副业入门:初学者的实战指南