Tuesday, November 26, 2013

Dynamic processing of Query using JDBC on blur


STEP -1

1. make input type like below which will call function loadXMLDoc on blur and will pass three arguements
a) url of jsp file where query will be executed by jsp i.e. "Views/Query/cancelQuery.jsp"
b)id(parameter for query)  i.e. "fid" used here
c) id of that part where to load the data(result). i.e. "err" used here
 ______________________________________________________________________
<input type="text" name="fid" onblur='if(this.length.value!=0){loadXMLDoc("Views/Query/cancelQuery.jsp","fid","err")}' id="fid"/>

<span id="err"></span></td>
_______________________________________________________________________


STEP -2

Add this script on top of page.
it receives the parameter and makes an ajax call (Ex- var urls = passedurl+"?ver=" + k;)  by combining url and parameter and gets the result and as per result process it. and feed result in required element.
_____________________________________________________________________
<script>
function loadXMLDoc(passedurl,id,loadingId) {
            var xmlhttp;
            var k = document.getElementById(id).value;
            var urls = passedurl+"?ver=" + k;

            if (window.XMLHttpRequest) {
                  xmlhttp = new XMLHttpRequest();
            } else {
                  xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
            xmlhttp.onreadystatechange = function() {
                  if (xmlhttp.readyState == 4) {
                        var result = xmlhttp.responseText;
                       
                        if(result==0){
                       
                            result="<br/><br/>&nbsp;&nbsp;&nbsp;<font color=red>FlightID: "+document.getElementById(id).value+" is not Available ..!!</font>";
                            document.getElementById(id).value="";   
                        }
                        else{
                       
                            result="<br/><br/>&nbsp;&nbsp;&nbsp;<font color=green>Flight is Available in Database</font>";                     
                        }
                        document.getElementById(loadingId).innerHTML=result;  
                  }
            };
            xmlhttp.open("GET", urls, true);
            xmlhttp.send();
      }
</script>
 _______________________________________________________________________

STEP -3

URL of JSP called by AJAX for executing the query using parameter.
 ______________________________________________________________________
<%@ page import="java.io.*,java.sql.*" %>
<%@ page contentType="text/html" pageEncoding="UTF-8"%>

<%
            String sn=request.getParameter("ver");

                    Class.forName("com.mysql.jdbc.Driver");
                    Connection con =DriverManager.getConnection("jdbc:mysql://localhost:3306/travportal","root","tiger");
                    Statement st=con.createStatement();
                    ResultSet rs = st.executeQuery("select fid from flight where fid="+sn);  // this is for name
                    if(rs.next())
                    {  
                         out.println("<font color=green>");
                         out.println("Flight is Availabe in Database");
                         out.println("</font>");
                    }else {
                         out.println("<font color=red>");
                         out.println("Flight is not Available in the Database");
                         out.println("</font>");
                    }
rs.close();
st.close();
con.close();
%>
 ______________________________________________________________________

Same thing can be done for called action files in STRUTS also.

Thursday, November 7, 2013

How to increase permSize of Tomcat

1. Double click on Tomcat Server icon and above overview will come
2. Go to Open Lauch Configuration then arguement option



3.  paste below properties.

-XX:MaxPermSize=512m
-XX:+UseConcMarkSweepGC -XX:+CMSPermGenSweepingEnabled -XX:+CMSClassUnloadingEnabled