Skip to content
Advertisement

Unable to Get the Proper Result : SQL Query Help Needed

Dear All,

rs3=st.executeQuery("select * from "+sdata[j]+" where Username='"+idata[i]+"'");
        while(rs3.next())
        {

                %><td><%out.println(rs3.getString("Final_Grade"));%></td><%


        }

In the above JSP Code,sdata[j] is the array of table names and idata[i] is the array of usernames. what i am trying to achieve is, to retrieve final_grade from the tables sdata[j] with the username==idata[i] . Since the username is existing in some table it displays the final grade, but when no record found in the table i want print it as “Null” instead of Final_Grade . Is this possible to implement?

Advertisement

Answer

Here is an answer based on my most recent comment:

rs3=st.executeQuery("select * from "+sdata[j]+" where Username='"+idata[i]+"'");

    flagRows = false;
    while(rs3.next())
    {
    %><td><%out.println(rs3.getString("Final_Grade"));%></td><%
    flagRows = true;
    }

    if (flagRows == false)
    {
    %><td><%out.println("NULL");%></td><%
    }
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement