Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script>
- var request=new XMLHttpRequest();
- function searchInfo(){
- var course_name=document.batch_form.course_name.value;
- var url="search.jsp?val="+course_name;
- try{
- request.onreadystatechange=function(){
- if(request.readyState==4){
- var val=request.responseText;
- document.getElementById('location').innerHTML=val;
- }
- }//end of function
- request.open("GET",url,true);
- request.send();
- }catch(e){alert("Unable to connect to server");}
- }
- </script>
- <%
- String course_name=request.getParameter("val");
- if(course_name==null||course_name.trim().equals("")){
- out.print("<p style='margin-left:145px;color:red;'>Please Enter Course Name...!</p>");
- }else{
- try{
- //Connection con = Connect.createConnection();
- Connection con=null;
- Class.forName("com.mysql.jdbc.Driver"); //loading MySQL drivers. This differs for database servers
- con = DriverManager.getConnection("jdbc:mysql://localhost:3306/new_database", "root", "");
- //attempting to connect to MySQL database
- PreparedStatement ps=con.prepareStatement("select * from course where course_name like '"+course_name+"%'");
- ResultSet rs=ps.executeQuery();
- if(!rs.isBeforeFirst()) {
- out.println("<p>No Record Found!</p>");
- }else{
- out.print("<table frame='box' width='' style='min-width:377px; margin-left:140px;' >");
- while(rs.next()){
- out.print("<tr><td class='form-control' style='font-size:13px;color:black;font-weight: bold;'>"+rs.getString(2)+"</td></tr>");
- //out.print(rs.getString(2));
- }
- out.print("</table>");
- }//end of else for rs.isBeforeFirst
- con.close();
- }catch(Exception e){out.print(e);}
- }//end of else
- %>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement