Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
this is my code for searching. But i want to print it on jsp page, cause i have used jquery for gui.

Java
try{
            
                       
            Class.forName(driver).newInstance();
             con = DriverManager.getConnection(url, "root", "root");
           // String sql = "Select uname from user_reg where uname='Shreya'";
            PreparedStatement ps=con.prepareStatement("Select * from user_reg_ml where uname='"+ name +"' OR email='"+ email +"'");
            
                     out.print("<table>");
                     out.print("<center><h1>Result:</h1></center>");
                     rs=ps.executeQuery();                
                     /* Printing column names */
                     ResultSetMetaData rsmd=rs.getMetaData();
                     out.print("<tr>");
               
                      out.print(" <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>");
                         out.print(" <script src=\"js/index.js\"></script>");
                     while(rs.next())
                        {
                         String friendname = rs.getString(2);                         
                         out.print("<td>"+rs.getString(2));                                   
                        // out.print("<button type=\"button\" onclick=friendnamebtn() id=\"btn_friends\">");
                       // out.print("<button type=\"button\" onclick='javascript:return friendnamebtn(this)' id=\"btn_friends\">");
                         out.print("<button type=\"button\" onclick='friendnamebtn(\""+ friendname +"\")' id=\"btn_friends\">");
                         out.print("Add" + friendname);
                         out.print("</button>");
                         out.print("</td></tr>");
                 //        out.print(rs.getString(2));
                     }
                     out.print("</table>");    

              }
            catch (Exception e2)
                {
                    out.print(e2);
                }
              finally{out.close();
                }
Posted
Updated 26-Oct-15 10:03am
v2
Comments
Richard Deeming 16-Oct-15 12:54pm    
Your code is vulnerable to SQL Injection[^].

NEVER use string concatenation to build a SQL query. ALWAYS use a parameterized query.
Luis Carlos Gonzalez Barcenas 26-Oct-15 15:48pm    
One idea could be make a jsp page and pass the results of the query by parameter and when you redirect to the page load the parameters and use in it as you prefer. Hope this help.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900