java - JDBC implementation: error with regard to parameters -


i working on creating jdbc program show list of grades selected student has in respective classes. however, keep getting error "procedure or function 'getstudenthistory' expects parameter '@studentid', not supplied."

here stored procedure in sql server:

create proc [dbo].[getstudenthistory]  @studentid int      select lastname, firstname, year, term, c.prefix + ' ' + cast(c.num char(3)) + ' - ' + sec.letter [course number],                  units, isnull(g.letter, ' ') grade     student s   inner join studentinsection sis     on s.studentid = sis.studentid  inner join section sec     on sec.sectionid = sis.sectionid  inner join course c     on c.courseid = sec.courseid left outer join grade g     on g.gradeid = sis.gradeid  inner join semester sem     on sem.semesterid = sec.semesterid      s.studentid = @studentid     order units desc 

here function within main class:

@suppresswarnings("resource") public static void showstudenthistory() {      system.out.print("\n please enter id of current student wanna see grades for");     system.out.print("\n==>");      scanner insertstudentid = new scanner(system.in);     int passedstudentid = insertstudentid.nextint() ;      student student = new student(passedstudentid, null, null);     list<student> students =  student.getstudenthistory(passedstudentid);     string tabs = "\t\t";     system.out.println("lastname"+ tabs + "firstname"+ tabs + "year"+ tabs + "term"+ tabs + "course number"+ tabs + "units"+ tabs + "grade");     system.out.println("---------"+ tabs + "---------"+ tabs + "--------"+ tabs + "-----------");   //            student tempstu = students.get(passedstudentid); //            system.out.println(tempstu.getmstudentid() + "\t\t\t" + //                    padright(tempstu.getmfirstname(), 15) + "\t\t" + //                    padright(tempstu.getmlastname(), 15) + "\t\t" + //                    tempstu.getmnum());      scanner kb = new scanner(system.in);     system.out.print("\nhit enter continue...");     string discard = kb.nextline(); 

and here accompanying function in student class:

public list<student> getstudenthistory(int studentid) {         list<student> students = new arraylist<>();        connection con = dbconnect();        preparedstatement ps = null;        resultset rs = null;        try {            ps = con.preparecall("getstudenthistory");            rs = ps.executequery();            // iterate through data in result set , load list //             while (rs.next()) { //                 students.add(new student(rs.getint("studentid") //                         , rs.getstring("lastname") //                         , rs.getstring("firstname") //                         , rs.getint("year") //                         , rs.getstring("course number") //                         , rs.getint("units") //                         , rs.getstring("grade") //                         )                                                    //                         ); //             }        } catch (sqlexception e) {            e.printstacktrace();        } {            if (rs != null) try { rs.close(); } catch(exception e) {}            if (ps != null) try { ps.close(); } catch(exception e) {}            if (con != null) try { con.close(); } catch(exception e) {}        }        return students;  } 

i know stored procedure works fine in sql server, getting confused how can implement stored proc has inner joins. of other stored procedures creating, updating, deleting, , displaying data work fine, make use of single student table. appreciate pointers community can give me, , i'd happy post more of code if thinks relevant finding solution problem.

the problem has nothing use of inner joins. stored procedure expects parameter, haven't provided it. should call like:

ps = con.preparecall("{call getstudenthistory(?)}"); ps.setint(1, studentid); resultset rs = ps.executequery(); 

see documentation of callablestatement.

as sidenote, i'd advise use java naming conventions: variables , parameters start lowercase letter, not uppercase (eg use studentid, not studentid).


Comments

Popular posts from this blog

jquery - How do you format the date used in the popover widget title of FullCalendar? -

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -