Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. <script>
  2. var request=new XMLHttpRequest();
  3.  
  4. function searchInfo(){
  5. var course_name=document.batch_form.course_name.value;
  6. var url="search.jsp?val="+course_name;
  7.  
  8. try{
  9. request.onreadystatechange=function(){
  10. if(request.readyState==4){
  11. var val=request.responseText;
  12. document.getElementById('location').innerHTML=val;
  13. }
  14. }//end of function
  15. request.open("GET",url,true);
  16. request.send();
  17. }catch(e){alert("Unable to connect to server");}
  18. }
  19. </script>
  20.  
  21. <%
  22. String course_name=request.getParameter("val");
  23. if(course_name==null||course_name.trim().equals("")){
  24. out.print("<p style='margin-left:145px;color:red;'>Please Enter Course Name...!</p>");
  25. }else{
  26. try{
  27.  
  28. //Connection con = Connect.createConnection();
  29. Connection con=null;
  30. Class.forName("com.mysql.jdbc.Driver"); //loading MySQL drivers. This differs for database servers
  31. con = DriverManager.getConnection("jdbc:mysql://localhost:3306/new_database", "root", "");
  32. //attempting to connect to MySQL database
  33. PreparedStatement ps=con.prepareStatement("select * from course where course_name like '"+course_name+"%'");
  34. ResultSet rs=ps.executeQuery();
  35.  
  36. if(!rs.isBeforeFirst()) {
  37. out.println("<p>No Record Found!</p>");
  38. }else{
  39. out.print("<table frame='box' width='' style='min-width:377px; margin-left:140px;' >");
  40. while(rs.next()){
  41. out.print("<tr><td class='form-control' style='font-size:13px;color:black;font-weight: bold;'>"+rs.getString(2)+"</td></tr>");
  42. //out.print(rs.getString(2));
  43.  
  44. }
  45. out.print("</table>");
  46. }//end of else for rs.isBeforeFirst
  47. con.close();
  48. }catch(Exception e){out.print(e);}
  49. }//end of else
  50. %>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement