Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Unable to Get the Proper Result : SQL Query Help Needed

Unable to Get the Proper Result : SQL Query Help Needed

Scheduled Pinned Locked Moved Database
databasejavadata-structureshelpquestion
3 Posts 3 Posters 5 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    arulsuju
    wrote on last edited by
    #1

    Dear All,

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

                %><%out.println(rs3.getString("Final\_Grade"));%><%
    
    
        }
    

    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?

    Richard DeemingR J 2 Replies Last reply
    0
    • A arulsuju

      Dear All,

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

                  %><%out.println(rs3.getString("Final\_Grade"));%><%
      
      
          }
      

      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?

      Richard DeemingR Offline
      Richard DeemingR Offline
      Richard Deeming
      wrote on last edited by
      #2

      Your code is vulnerable to SQL Injection[^]. NEVER use string concatenation to build a SQL query. ALWAYS use a parameterized query. Everything you wanted to know about SQL injection (but were afraid to ask) | Troy Hunt[^] How can I explain SQL injection without technical jargon? | Information Security Stack Exchange[^] Query Parameterization Cheat Sheet | OWASP[^]


      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

      1 Reply Last reply
      0
      • A arulsuju

        Dear All,

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

                    %><%out.println(rs3.getString("Final\_Grade"));%><%
        
        
            }
        

        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?

        J Offline
        J Offline
        Jochen Arndt
        wrote on last edited by
        #3

        Just count the returned rows:

        int count = 0;
        while (rs3.next())
        {
        count++;
        // Access row data here
        }
        if (count == 0)
        {
        // No matching row found
        %>Null<%
        }

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups