数据库查询问题,请大家帮忙看看

qq_35746856 2018-03-20 03:36:16
public static List getSalaryList(double jiaBanFei, double qingJiaFei,
double queQinFei, String year, String month) {
List list = new ArrayList();
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
int year1 = Integer.parseInt(year);
int month1 = Integer.parseInt(month);
boolean has = false;
try {
conn = DB.getConnection();
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_READ_ONLY);
String sql = "select count(*) from salaryinfo where syear='" + year1
+ "' and smonth='" + month1 + "'";//查询这个月的薪资表是否生成

rs = stmt.executeQuery(sql);
if (rs.next()) {
int i = rs.getInt(1);

if (i > 0) {

has = true;
}
}
rs.close();

if (has == false) //生成薪资表
{
}

sql = "select salaryinfo.impId,imployeeinfo.impName,salaryinfo.syear," //这里的salaryinfo.syear为char
+ "salaryinfo.smonth,salaryinfo.sBase,salaryinfo.sExtra," //这里的salaryinfo.smonth为char
+ "salaryinfo.sHoliday,salaryinfo.sAbsence,salaryinfo.sTotal,"
+ "salaryinfo.sState from salaryinfo,imployeeinfo "
+ "where salaryinfo.impId=imployeeinfo.impId";


rs = stmt.executeQuery(sql);

while (rs.next()) {
String impId1 = rs.getString("impId");
String impName = new String(rs.getString("impName"));
String opyear = rs.getString("syear");
String opmonth = rs.getString("smonth");
double sBase = rs.getDouble("sBase");
double sExtra = rs.getDouble("sExtra");
double sHoliday = rs.getDouble("sHoliday");
double sAbsence = rs.getDouble("sAbsence");
double sTotal = rs.getDouble("sTotal");
int sState = rs.getInt("sState");
SalaryRecord sr = new SalaryRecord(impId1, impName, opyear,
opmonth, sBase, sExtra, sHoliday, sAbsence, sTotal,sState);
list.add(sr);
}
}
红字这我想选取符合用户输入的year1和month1的数据,但总是要么显示没数据要么出错,请大家帮我看一下该怎么修改
...全文
1055 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
I维生素I 2018-04-27
  • 打赏
  • 举报
回复
发一下异常信息
乐之者v 2018-04-11
  • 打赏
  • 举报
回复
你的where条件写少了吧。。 sql也可以写精简些。

select a.impId,b.impName,a.syear,a.smonth,a.sBase
from salaryinfo  a
inner join    imployeeinfo  b  
 on   a.impId=b.impId


G.Jagger 2018-04-10
  • 打赏
  • 举报
回复
看懵了,你参数从哪里传进去的,sql里没有条件输入啊???
  • 打赏
  • 举报
回复
没看明白,报错信息发一下吧
Sunyiban 2018-03-20
  • 打赏
  • 举报
回复
1.你这个查询的sql没有设置输入条件,然后你想选取符合用户输入条件的数据。那就用case when。 2.报什么错,贴出来。

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧