package com.ape.dao.ImpI;
import com.ape.bean.BanJi;
import com.ape.bean.student;
import com.ape.dao.BaseDao;
import com.ape.dao.DaoUtil;
import com.ape.dao.IBanJiDao;
import sun.invoke.util.BytecodeName;
import java.util.ArrayList;
import java.util.List;
public class BanJiDaoImpI extends BaseDao implements IBanJiDao {
@Override
public List<BanJi> findAllBanJiAndStudent() {
List<BanJi> bjList = new ArrayList<BanJi>();
String sql = "select * from class left join student on class.classid = student.classid";
try {
rs = query(sql);
while (rs.next()) {
int index = -1; //获取集合中找到班级的下标
for (int i = 0; i < bjList.size(); i++) {
if (rs.getInt("classid") == bjList.get(i).getClassid()) {
index = i;
break;
}
}
if (index == -1) {
//班级从来没有出现过才需要new班级
BanJi bj = new BanJi();
bj.setClassid(rs.getInt("classid"));
bj.setClassname(rs.getString("classname"));
student s = new student();
s.setBirth(rs.getDate("birthday"));
s.setClassid(rs.getInt("classid"));
s.setSid(rs.getInt("sid"));
s.setSname(rs.getString("sname"));
s.setSsex(rs.getString("ssex"));
List<student> sList = new ArrayList<student>();
sList.add(s);
bj.setsList(sList);
bjList.add(bj);
}else {
student s = new student();
s.setBirth(rs.getDate("birthday"));
s.setClassid(rs.getInt("classid"));
s.setSid(rs.getInt("sid"));
s.setSname(rs.getString("sname"));
s.setSsex(rs.getString("ssex"));
List<student> sList = new ArrayList<student>();
sList.add(s);
BanJi banJi = bjList.get(index);
banJi.getsList().add(s);
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
DaoUtil.closeResource(connection, preparedStatement, rs);
}
return bjList;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
JDBC之多表联查获取数据的操作案例
![preview](https://csdnimg.cn/release/downloadcmsfe/public/img/white-bg.ca8570fa.png)
共10个文件
java:9个
iml:1个
![preview-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/scale.ab9e0183.png)
0 下载量 26 浏览量
2024-08-19
20:55:43
上传
评论
收藏 7KB ZIP 举报
温馨提示
JDBC之多表联查获取数据的操作案例
资源推荐
资源详情
资源评论
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![application/x-zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![text/x-java](https://img-home.csdnimg.cn/images/20210720083646.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![application/msword](https://img-home.csdnimg.cn/images/20210720083327.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
收起资源包目录
![package](https://csdnimg.cn/release/downloadcmsfe/public/img/package.f3fc750b.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
共 10 条
- 1
资源评论
![avatar-default](https://csdnimg.cn/release/downloadcmsfe/public/img/lazyLogo2.1882d7f4.png)
![avatar](https://profile-avatar.csdnimg.cn/fefe3909fb7e4ca1a1b3d3a839eafcc2_weixin_64562166.jpg!1)
JY_H
- 粉丝: 160
- 资源: 11
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![voice](https://csdnimg.cn/release/downloadcmsfe/public/img/voice.245cc511.png)
![center-task](https://csdnimg.cn/release/downloadcmsfe/public/img/center-task.c2eda91a.png)
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback-tip](https://img-home.csdnimg.cn/images/20220527035111.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![dialog-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/green-success.6a4acb44.png)