合作对象:李佳岳
今日所完成代码:select函数、检验输入的站点在几号线的函数checkstation、带参数的select函数、站名输出函数substation
package dao;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import bean.Bean;
import dbutil.DButil;
public class Dao {
public String[] substation(Bean[] sub,String s1,String s2)
{
ArrayList<String> stationlist =new ArrayList<String>();
int start=0;
int end=0;
int money;
int i;
for(i=0;i<sub.length;i++)
{
if(sub[i].getName().equals(s1))
start=i;
}//确定起始站
for(i=0;i<sub.length;i++)
{
if(sub[i].getName().equals(s2))
end=i;
}//确定终点站
if(start<end)
{
for(i=start;i<=end;i++)
{
stationlist.add(sub[i].getName());
}//输出站点信息
}
else
{
for(i=start;i>=end;i--)
{
stationlist.add(sub[i].getName());
}//输出站点信息
}
return stationlist.toArray(new String[stationlist.size()]);
}
public int checkstation(String start)
{
Dao dao=new Dao();
int i;
for(i=0;i<dao.selectno1().length;i++)
{
if(dao.selectno1()[i].getName().equals(start))
{
return 1;
}
}
for(i=0;i<dao.selectno2().length;i++)
{
if(dao.selectno2()[i].getName().equals(start))
{
return 2;
}
}
for(i=0;i<dao.selectno3().length;i++)
{
if(dao.selectno3()[i].getName().equals(start))
{
return 3;
}
return 0;
}
public Bean[] select(int n)
{
Bean[] a=new Bean[] {};
Dao dao=new Dao();
if(n==1)
return dao.selectno1();
if(n==2)
return dao.selectno2();
if(n==3)
return dao.selectno3();
else
return a;
}
public Bean[] selectno1()
{
ArrayList<Bean> list=new ArrayList();
Connection connection = DButil.getConn();
Statement statement=null;
ResultSet rs = null;
try
{
statement = connection.createStatement();
// 要执行的SQL语句
String sql = "select * from no1 ";
// 结果集
rs = statement.executeQuery(sql);
while(rs.next())
{
Bean selectbean=new Bean();
String name = rs.getString("name");
int number = rs.getInt("id");
String nearline = rs.getString("nearline");
selectbean.setName(name);
selectbean.setNumber(number);
selectbean.setNearline(nearline);
list.add(selectbean);
}
} catch (Exception e)
{
e.printStackTrace();
} finally
{
DButil.close(rs, statement, connection);
}
return list.toArray(new Bean[list.size()]);
}//获取一号线的所有信息
public Bean[] selectno2()
{
ArrayList<Bean> list=new ArrayList();
Connection connection = DButil.getConn();
Statement statement=null;
ResultSet rs = null;
try
{
statement = connection.createStatement();
// 要执行的SQL语句
String sql = "select * from no2 ";
// 结果集
rs = statement.executeQuery(sql);
while(rs.next())
{
Bean selectbean=new Bean();
String name = rs.getString("name");
int number = rs.getInt("id");
String nearline = rs.getString("nearline");
selectbean.setName(name);
selectbean.setNumber(number);
selectbean.setNearline(nearline);
list.add(selectbean);
}
} catch (Exception e)
{
e.printStackTrace();
} finally
{
DButil.close(rs, statement, connection);
}
return list.toArray(new Bean[list.size()]);
}//获取二号线的所有信息
public Bean[] selectno3()
{
ArrayList<Bean> list=new ArrayList();
Connection connection = DButil.getConn();
Statement statement=null;
ResultSet rs = null;
try
{
statement = connection.createStatement();
// 要执行的SQL语句
String sql = "select * from no3 ";
// 结果集
rs = statement.executeQuery(sql);
while(rs.next())
{
Bean selectbean=new Bean();
String name = rs.getString("name");
int number = rs.getInt("id");
String nearline = rs.getString("nearline");
selectbean.setName(name);
selectbean.setNumber(number);
selectbean.setNearline(nearline);
list.add(selectbean);
}
} catch (Exception e)
{
e.printStackTrace();
} finally
{
DButil.close(rs, statement, connection);
}
return list.toArray(new Bean[list.size()]);
}//获取三号线的全部信息
}
标签:结对,return,String,rs,三月,Bean,selectbean,new,十八日 From: https://www.cnblogs.com/mine-my/p/17231740.html