String count with substring

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sang
    New Member
    • Sep 2006
    • 83

    #46
    Originally posted by r035198x
    Do not change the structure of your main method, just change the part that called the function and replace that part with the function itself with slight modifications. Why don't you want to call the function?
    I do this program in jsp. I don't know how to call the function in jsp because the inputs are taken from the database. i think the main method is easly implemented in jsp. I am also do this in jsp but it print the keywords only the count values is 0. so that i ask how can i do this without function call.

    Please help to do this

    Thanks and Regards
    Sang

    Comment

    • r035198x
      MVP
      • Sep 2006
      • 13225

      #47
      Originally posted by sang
      I do this program in jsp. I don't know how to call the function in jsp because the inputs are taken from the database. i think the main method is easly implemented in jsp. I am also do this in jsp but it print the keywords only the count values is 0. so that i ask how can i do this without function call.

      Please help to do this

      Thanks and Regards
      Sang

      Code:
      public class strcount {
      	public static void main(String arg[]) {
      		String sentence = "java,jsp,c,dhtml,unix";
      		String word = "java,html";
      		String temp[] = word.split(",");
      		int count = 0;
      		for(int i = 0; i < temp.length;i++) {
      			System.out.print(temp[i]+" appears : ");
      			count = 0;
      			int wordLength = temp[i].length();
      			for(int j = 0; j < sentence.length() - wordLength; j++) {
      			   if(temp[i].equals(sentence.substring(j, j + wordLength))) {
      				   count++;
      			   }
      			}
      		  	System.out.print(count + " times");
      			System.out.println();
      		}
      
      	}
      
      
       }

      Comment

      • sang
        New Member
        • Sep 2006
        • 83

        #48
        Originally posted by r035198x
        Code:
        public class strcount {
        	public static void main(String arg[]) {
        		String sentence = "java,jsp,c,dhtml,unix";
        		String word = "java,html";
        		String temp[] = word.split(",");
        		int count = 0;
        		for(int i = 0; i < temp.length;i++) {
        			System.out.print(temp[i]+" appears : ");
        			count = 0;
        			int wordLength = temp[i].length();
        			for(int j = 0; j < sentence.length() - wordLength; j++) {
        			   if(temp[i].equals(sentence.substring(j, j + wordLength))) {
        				   count++;
        			   }
        			}
        		  	System.out.print(count + " times");
        			System.out.println();
        		}
        
        	}
        
        
         }
        Hello Sir,
        I want to use above code in jsp page to print the keywords and count. But the count values is not correct .

        please help to do and also how can i place this code in jsp.
        my code.
        Code:
        <table  border="0" cellspacing="4">
          <tr>
            
            <td width="241" align="right" valign="middle" bgcolor="#0F6484"><div align="center" class="joblisting">Keyword</div></td>
            <td width="122" valign="middle" bgcolor="#0F6484"><div align="center" class="joblisting">NoOfCount&nbsp;&nbsp;</div></td>
          </tr>
          <%
        	String UserId=request.getParameter("UserId");
        	String JobRefNo=request.getParameter("JobRefNo");
        	String Resume=request.getParameter("Resume");
        		
        	String sql1 = "select Keywords from JOB_ORDER a, JOB_APPLICATION b, CAN_RESUME c where a.JobRefNo=b.JobRefNo and a.JobRefNo="+ JobRefNo+" and c.UserId="+UserId;
        		
        		
        	Statement stm1 = dbConnection.createStatement();
        		ResultSet rs1 = null;
        		rs1 = stm1.executeQuery(sql1);
        		rs1.next();
        		String Keywords=rs1.getString(1);
        		String temp[] = Keywords.split(",");
        		for(int i = 0; i < temp.length;i++) {
        		
        		
        %>
          <tr>
            
            <td align="left" valign="middle" class="altrow2"><%= temp[i] %></td>
        	<% 
        	
        	String sql2 ="select Resume from CAN_RESUME a,JOB_APPLICATION b,JOB_ORDER c where b.JobRefNo=c.JobRefNo and a.UserId=b.UserId and a.UserId="+UserId;
        	Statement stm2 = dbConnection.createStatement();
        		ResultSet rs2 = null;
        		rs2 = stm2.executeQuery(sql2);
        		rs2.next();
        		String Resume1=rs2.getString(1);
        		%>
        		
        	<%!int count = 0;
        	int j;
        	 %>
        	 
        	<% int KeywordsLength = temp[i].length();
        			for( j = 0; j < Resume1.length() - KeywordsLength; j++) {
        	
        	   if(temp[i].equals(Resume1.substring(j, j + KeywordsLength))) {
        				   count++; 
        	%>		   
        		
        	<%  } %>
        	<%	} %>
        	
            <td align="center" valign="middle" class="altrow2"><% out.print(count); %></td>
          </tr>
          <% } %>
          <tr>
            <td colspan="3" align="center"><img src="/epc/img/close.gif"  width="53" height="19"   onClick="javascript: window.close()"/> </td>
        Please help to correct the count values
        Thnaks and Regards
        Sang

        Comment

        • r035198x
          MVP
          • Sep 2006
          • 13225

          #49
          Originally posted by sang
          Hello Sir,
          I want to use above code in jsp page to print the keywords and count. But the count values is not correct .

          please help to do and also how can i place this code in jsp.
          my code.
          Code:
          <table border="0" cellspacing="4">
          <tr>
           
          <td width="241" align="right" valign="middle" bgcolor="#0F6484"><div align="center" class="joblisting">Keyword</div></td>
          <td width="122" valign="middle" bgcolor="#0F6484"><div align="center" class="joblisting">NoOfCount&nbsp;&nbsp;</div></td>
          </tr>
          <%
          	String UserId=request.getParameter("UserId");
          	String JobRefNo=request.getParameter("JobRefNo");
          	String Resume=request.getParameter("Resume");
           
          	String sql1 = "select Keywords from JOB_ORDER a, JOB_APPLICATION b, CAN_RESUME c where a.JobRefNo=b.JobRefNo and a.JobRefNo="+ JobRefNo+" and c.UserId="+UserId;
           
           
          	Statement stm1 = dbConnection.createStatement();
          		ResultSet rs1 = null;
          		rs1 = stm1.executeQuery(sql1);
          		rs1.next();
          		String Keywords=rs1.getString(1);
          		String temp[] = Keywords.split(",");
          		for(int i = 0; i < temp.length;i++) {
           
           
          %>
          <tr>
           
          <td align="left" valign="middle" class="altrow2"><%= temp[i] %></td>
          	<% 
           
          	String sql2 ="select Resume from CAN_RESUME a,JOB_APPLICATION b,JOB_ORDER c where b.JobRefNo=c.JobRefNo and a.UserId=b.UserId and a.UserId="+UserId;
          	Statement stm2 = dbConnection.createStatement();
          		ResultSet rs2 = null;
          		rs2 = stm2.executeQuery(sql2);
          		rs2.next();
          		String Resume1=rs2.getString(1);
          		%>
           
          	<%!int count = 0;
          	int j;
          	 %>
           
          	<% int KeywordsLength = temp[i].length();
          			for( j = 0; j < Resume1.length() - KeywordsLength; j++) {
           
          	 if(temp[i].equals(Resume1.substring(j, j + KeywordsLength))) {
          				 count++; 
          	%>		 
           
          	<% } %>
          	<%	} %>
           
          <td align="center" valign="middle" class="altrow2"><% out.print(count); %></td>
          </tr>
          <% } %>
          <tr>
          <td colspan="3" align="center"><img src="/epc/img/close.gif" width="53" height="19" onClick="javascript: window.close()"/> </td>
          Please help to correct the count values
          Thnaks and Regards
          Sang
          What answers are you getting and what are you expecting?

          Comment

          • sang
            New Member
            • Sep 2006
            • 83

            #50
            Originally posted by r035198x
            What answers are you getting and what are you expecting?
            The count value is incorrect. That is the sql1 gets the keyword form the dataabase and split it.
            The sql2 gets the resume from database and check the resume with the keyword.
            I want to count the noof keywords appears in the resume.
            in normal java program it works well but in the jsp i got incorrect count values.
            The count values are changed after refeshing (every time) of the page.

            This is most urget so please help me as soon as possible

            Please hel pto correct it
            Thanyou,
            Sang

            Comment

            • r035198x
              MVP
              • Sep 2006
              • 13225

              #51
              Originally posted by sang
              The count value is incorrect. That is the sql1 gets the keyword form the dataabase and split it.
              The sql2 gets the resume from database and check the resume with the keyword.
              I want to count the noof keywords appears in the resume.
              in normal java program it works well but in the jsp i got incorrect count values.
              The count values are changed after refeshing (every time) of the page.

              This is most urget so please help me as soon as possible

              Please hel pto correct it
              Thanyou,
              Sang

              First.

              Are you using a different Resume for each keyword?

              Code:
               
              for(int i = 0; i < temp.length;i++) {
              
              
              %>
              <tr>
              
              <td align="left" valign="middle" class="altrow2"><%= temp[i] %></td>
              <% 
              
              String sql2 ="select Resume from CAN_RESUME a,JOB_APPLICATION b,JOB_ORDER c where b.JobRefNo=c.JobRefNo and a.UserId=b.UserId and a.UserId="+UserId;
              Statement stm2 = dbConnection.createStatement();
              ResultSet rs2 = null;
              If not you should get the resume only once

              Code:
               
              String sql2 ="select Resume from CAN_RESUME a,JOB_APPLICATION b,JOB_ORDER c where b.JobRefNo=c.JobRefNo and a.UserId=b.UserId and a.UserId="+UserId;
              Statement stm2 = dbConnection.createStatement();
              ResultSet rs2 = null;
              for(int i = 0; i < temp.length;i++) { 
              //....

              Comment

              • sang
                New Member
                • Sep 2006
                • 83

                #52
                Originally posted by r035198x
                First.

                Are you using a different Resume for each keyword?

                Code:
                 
                for(int i = 0; i < temp.length;i++) {
                
                
                %>
                <tr>
                
                <td align="left" valign="middle" class="altrow2"><%= temp[i] %></td>
                <% 
                
                String sql2 ="select Resume from CAN_RESUME a,JOB_APPLICATION b,JOB_ORDER c where b.JobRefNo=c.JobRefNo and a.UserId=b.UserId and a.UserId="+UserId;
                Statement stm2 = dbConnection.createStatement();
                ResultSet rs2 = null;
                If not you should get the resume only once

                Code:
                 
                String sql2 ="select Resume from CAN_RESUME a,JOB_APPLICATION b,JOB_ORDER c where b.JobRefNo=c.JobRefNo and a.UserId=b.UserId and a.UserId="+UserId;
                Statement stm2 = dbConnection.createStatement();
                ResultSet rs2 = null;
                for(int i = 0; i < temp.length;i++) { 
                //....
                Yes i am using different resume for keywords.

                How can i get the Resume

                Comment

                • r035198x
                  MVP
                  • Sep 2006
                  • 13225

                  #53
                  Originally posted by sang
                  Yes i am using different resume for keywords.

                  How can i get the Resume
                  But you are getting the same value of resume everytime because in the for loop you keep getting the first row of the same table.

                  Comment

                  • sang
                    New Member
                    • Sep 2006
                    • 83

                    #54
                    Originally posted by r035198x
                    But you are getting the same value of resume everytime because in the for loop you keep getting the first row of the same table.
                    How can i get the Resume. Please Give me what correction i can made in my query its very urgent.

                    Thankyou
                    Sang

                    Comment

                    • sang
                      New Member
                      • Sep 2006
                      • 83

                      #55
                      Originally posted by sang
                      How can i get the Resume. Please Give me what correction i can made in my query its very urgent.

                      Thankyou
                      Sang
                      My Table Details are give below
                      Code:
                       JOB_APPLICATION;
                      +---------------+--------------+------+-----+---------+-------+
                      | Field         | Type         | Null | Key | Default | Extra |
                      +---------------+--------------+------+-----+---------+-------+
                      | UserId        | int(11)      | NO   | PRI | 0       |       |
                      | JobRefNo      | int(11)      | NO   | PRI | 0       |       |
                      | A1            | varchar(10)  | YES  |     |         |       |
                      | A2            | varchar(10)  | YES  |     |         |       |
                      | A3            | varchar(10)  | YES  |     |         |       |
                      | A4            | varchar(10)  | YES  |     |         |       |
                      | A5            | varchar(10)  | YES  |     |         |       |
                      | AppliedDate   | datetime     | YES  |     |         |       |
                      | Status        | varchar(30)  | YES  |     |         |       |
                      | Rank          | int(11)      | YES  |     |         |       |
                      | NoticePeriod  | int(11)      | YES  |     |         |       |
                      | RangeFrom     | int(11)      | YES  |     |         |       |
                      | RangeTo       | int(11)      | YES  |     |         |       |
                      | Currency      | varchar(15)  | YES  |     |         |       |
                      | SalaryPeriod  | varchar(15)  | YES  |     |         |       |
                      | MatchKeywords | varchar(300) | YES  |     |         |       |
                      | NoOfMatch     | int(11)      | YES  |     |         |       |
                      +---------------+--------------+------+-----+---------+-------+
                      JOB_ORDER;
                      +-------------------+--------------+------+-----+---------+----------------+
                      | Field             | Type         | Null | Key | Default | Extra          |
                      +-------------------+--------------+------+-----+---------+----------------+
                      | JobRefNo          | int(11)      | NO   | PRI |         | auto_increment |
                      | JobTitle          | varchar(200) | YES  |     |         |                |
                      | JobDescription    | text         | YES  |     |         |                |
                      | JobRequirement    | text         | YES  |     |         |                |
                      | SalaryDescription | varchar(100) | YES  |     |         |                |
                      | Category1         | varchar(50)  | YES  |     |         |                |
                      | SubCategory1      | varchar(50)  | YES  |     |         |                |
                      | Category2         | varchar(50)  | YES  |     |         |                |
                      | SubCategory2      | varchar(50)  | YES  |     |         |                |
                      | Category3         | varchar(50)  | YES  |     |         |                |
                      | SubCategory3      | varchar(50)  | YES  |     |         |                |
                      | OtherSkills       | varchar(200) | YES  |     |         |                |
                      | Experience        | int(11)      | YES  |     |         |                |
                      | Education         | varchar(50)  | YES  |     |         |                |
                      | Country           | varchar(50)  | YES  |     |         |                |
                      | NoOfPosition      | int(11)      | YES  |     |         |                |
                      | JobType           | varchar(50)  | YES  |     |         |                |
                      | PostedDate        | date         | YES  |     |         |                |
                      | ValidUpto         | date         | YES  |     |         |                |
                      | GroupRefNo        | varchar(20)  | YES  |     |         |                |
                      | Status            | varchar(30)  | YES  |     |         |                |
                      | Q1                | varchar(200) | YES  |     |         |                |
                      | A1                | varchar(10)  | YES  |     |         |                |
                      | Q2                | varchar(200) | YES  |     |         |                |
                      | A2                | varchar(10)  | YES  |     |         |                |
                      | Q3                | varchar(200) | YES  |     |         |                |
                      | A3                | varchar(10)  | YES  |     |         |                |
                      | Q4                | varchar(200) | YES  |     |         |                |
                      | A4                | varchar(10)  | YES  |     |         |                |
                      | Q5                | varchar(200) | YES  |     |         |                |
                      | A5                | varchar(10)  | YES  |     |         |                |
                      | Region            | varchar(40)  | YES  |     |         |                |
                      | Language          | varchar(40)  | YES  |     |         |                |
                      | Keywords          | varchar(300) | YES  |     |         |                |
                      | MinMatch          | int(11)      | YES  |     |         |                |
                      +-------------------+--------------+------+-----+---------+----------------+
                      
                      CAN_RESUME;
                      +-----------------+-------------+------+-----+---------+-------+
                      | Field           | Type        | Null | Key | Default | Extra |
                      +-----------------+-------------+------+-----+---------+-------+
                      | UserId          | int(11)     | NO   | PRI |         |       |
                      | Resume          | longblob    | NO   |     |         |       |
                      | LastUpdate      | date        | NO   |     |         |       |
                      | ResumeStatus    | varchar(10) | YES  |     |         |       |
                      | EditedResume    | longblob    | YES  |     |         |       |
                      | EditedResumePDF | longblob    | YES  |     |         |       |
                      | EditedDate      | date        | YES  |     |         |       |
                      | TxtStatus       | int(11)     | YES  |     |         |       |
                      | TxtResume       | mediumtext  | YES  |     |         |       |
                      +-----------------+-------------+------+-----+---------+-------+
                      How can i get the Resume using this tables

                      Comment

                      • r035198x
                        MVP
                        • Sep 2006
                        • 13225

                        #56
                        Originally posted by sang
                        How can i get the Resume. Please Give me what correction i can made in my query its very urgent.

                        Thankyou
                        Sang
                        It really depends on how you have stored your values and what it is that you want to retrieve. Do you want to search all the rows for every word?

                        Comment

                        • sang
                          New Member
                          • Sep 2006
                          • 83

                          #57
                          Originally posted by r035198x
                          It really depends on how you have stored your values and what it is that you want to retrieve. Do you want to search all the rows for every word?
                          In my program i am storing different resumes for different Userid.

                          and also different keywords for different JobRefNo

                          i want to retrive the keywords and the particular count for the JobRefNo which is matching to the resume. More than one Userid matching to the one JobRefNo so that i want to select it by condition both JobRefNo and Userid mathc to the Resume.

                          The keywords are retrive corectly but resumes are not get properly
                          How can i get it

                          Please help to do this
                          Thankyou

                          Comment

                          • sang
                            New Member
                            • Sep 2006
                            • 83

                            #58
                            Originally posted by sang
                            In my program i am storing different resumes for different Userid.

                            and also different keywords for different JobRefNo

                            i want to retrive the keywords and the particular count for the JobRefNo which is matching to the resume. More than one Userid matching to the one JobRefNo so that i want to select it by condition both JobRefNo and Userid mathc to the Resume.

                            The keywords are retrive corectly but resumes are not get properly
                            How can i get it

                            Please help to do this
                            Thankyou
                            How can i get the Resume with the userid?
                            Please help to solve my problem

                            Thanks and Regards
                            Sang

                            Comment

                            • r035198x
                              MVP
                              • Sep 2006
                              • 13225

                              #59
                              Originally posted by sang
                              How can i get the Resume with the userid?
                              Please help to solve my problem

                              Thanks and Regards
                              Sang
                              I'll try to get the database experts onto it then, I expect they'll want a bit more info though because I'm not really sure about what you are saying.

                              Comment

                              • NeoPa
                                Recognized Expert Moderator MVP
                                • Oct 2006
                                • 32662

                                #60
                                Originally posted by sang
                                How can i get the Resume with the userid?
                                Please help to solve my problem

                                Thanks and Regards
                                Sang
                                Sang,
                                I'm not here to help with your code, but I may be able to help with the SQL part.
                                Can you post exactly what SQL you have in your current query and exactly what is not working as you would hope please.

                                Comment

                                Working...