oracle - How to have multiple Select Statements in a Result Set in Java -
the problem running want select column , sum values. want sum column in same table. object take these 2 summed columns , subtract them output. use taking vacation times. every week employee gains hours of vacation. when used in different column. need come total of vacation left can use. have:
try { //getting information employee_time_log vacation statement vacationlogstmt = dbconn.createstatement(); resultset vacationlogset = vacationlogstmt.executequery( "(select sum(vacation_gained) employee_time_log employee_id_number = " +userinputidnumber + "), " + "(select sum(vacation_used) employee_time_log employee_id_number = " +userinputidnumber + "), " + "group vacation_gained, vacation_used"); vacationlogset.next(); string strvacationearned = vacationlogset.getstring(1); string strvacationused = vacationlogset.getstring(2); double vacationearned = double.parsedouble(strvacationearned); double vacationused = double.parsedouble(strvacationused); double totalvacation = (vacationearned - vacationused); string strtotalvacation =double.tostring(totalvacation); txtvacationtotal.settext(strtotalvacation); } catch (sqlexception e) { //throw new jboexception(e); system.err.println(e); string connectionerror = "problem database, please contact mis."; joptionpane.showmessagedialog(new jframe(), connectionerror, "database error",joptionpane.error_message); txtusersignin.settext(""); txtusersignin.requestfocus(); }
i getting error: java.sql.sqlsyntaxerrorexception: ora-00933: sql command not ended
can done in 1 result set? or need make separate result sets this.
there couple of problems sql. first, can not have multiple selects separated commas. instead, should have 1 select multiple columns. second, should not group vacation_gained, vacation_used because using these fields in aggregate functions. sql should follows:
"(select sum(vacation_gained), sum(vacation_used) employee_time_log employee_id_number = " + userinputidnumber + ")";
alternatively, if interested in vacation time left, can math part of query well:
"(select sum(vacation_gained) - sum(vacation_used) total_vacation employee_time_log employee_id_number = " + userinputidnumber + ")";
Comments
Post a Comment