当前位置:网站首页>打印数据库返回的查询数据是null,或者是默认值。与数据库返回的值不相符
打印数据库返回的查询数据是null,或者是默认值。与数据库返回的值不相符
2022-07-25 19:33:00 【似嘲似笑】
测试环境 IDEA2021
在打印班级平均分的时候,发现所有班级平均分都是0.0

先去检查了一遍SQL语句,确认没有错误
public List<ClassAvgScore> queryClassAvgScore(){
return scoreDAO.QueryMany("SELECT ClassRoom,AVG(score) AS score FROM Student GROUP BY ClassRoom ORDER BY ClassRoom ASC,AVG(score)DESC;",ClassAvgScore.class);
}数据库学生表

检查了好久才发现用于接收查询结果的映射类属性名(不知道具体该怎么称呼)写错了。没有和数据库表的列名相同
private int ClassRoom;
private double AvgScore;
public double getAvgScore() {
return AvgScore;
}
public void setAvgScore(double avgScore) {
AvgScore = avgScore;
}
public int getClassRoom() {
return ClassRoom;
}在映射类里写的是AvgScore 而数据库表的列名是score 导致数据无法装进。
解决办法
把映射类里面的属性名改为和和数据库表的列名一样就解决了
注意:我这条查寻语句把列名重命名了 as score ,所以映射类属性名要改成重命名后的名字而不是表的列名(虽然我重命名后和原表列名一样,哈哈哈)。注意一下就行
边栏推荐
- Network packet multi-layer transmission demonstration
- [CSAPP Practice Problem 2.32] tsub_ok(int x, int y)判断补码减法是否溢出
- leetcode刷题:动态规划07(不同的二叉搜索树)
- Common misunderstandings caused by a time reporting assistant of Blue Bridge Cup basic questions
- AAAI 2022 | GAN的结构有“指纹”吗?从伪造图像溯源生成网络结构
- GBASE 8s UDR内存管理_02_mi_dalloc
- Imeta | sangerbox: interactive integrated clinical information analysis platform
- Illegal mix of collations for operation ‘UNION‘(bug记录)
- 某公司网络设计与规划
- Introduction of this course (Introduction to machine learning)
猜你喜欢

新瓶装老酒--近期APT32(海莲花)组织攻击活动样本分析

Imeta | sangerbox: interactive integrated clinical information analysis platform

Monitor MySQL based on MySQL exporter

【刷题记录】21. 合并两个有序链表

Beihang and other "deep learning event extraction" literature review paper, 27 page PDF describes the current trend

Wxss template style and WXS scripting language for wechat applet development

授权无线通信标准

Wechat campus maintenance application applet graduation design finished product of applet completion work (3) background function

InTouch advanced alarm (alarm filtering)

鸿蒙-大喵计算画板-简介
随机推荐
what is qml in qt
Flutter tips: optimizing the buildcontext you use
[applet development] common components and basic usage details
Beihang and other "deep learning event extraction" literature review paper, 27 page PDF describes the current trend
Wechat applet 10 - wechat template
Wechat campus maintenance and repair applet graduation design finished product of applet completion work (4) opening report
balanced binary tree
The finished product of wechat campus maintenance and repair applet graduation design (1) development outline
On interface encryption
【刷题记录】21. 合并两个有序链表
[iniparser] simple use of the project configuration tool iniparser
A good way to generate interface documents efficiently
Hongmeng - Damiao computing Sketchpad - Introduction
Binary tree visualization
Code sharing of social chat platform developed by dating website (III)
Selenium runs slowly - speed up by setting selenium load policy
Old wine in new bottles -- sample analysis of recent apt32 (sea Lotus) organizational attacks
NPM semantic version control, solution console prop being mutated: "placement" error
英诚医院内部网络规划与设计
Why learn service grid istio