Results 1 to 3 of 3
  1. #1
    shuvra_pan is offline Member
    Join Date
    Jun 2008
    Posts
    10
    Rep Power
    0

    Default increment prob on jsp

    <%@page import="java.sql.*"%>
    <%@page import="java.io.*"%>
    <%@include file="dbconnection.jsp"%>
    <%


    String loc=request.getParameter("Location");
    String qul=request.getParameter("Qualification");
    String pro=request.getParameter("Programming");
    String db=request.getParameter("Database");
    String plat=request.getParameter("Platform");

    Statement stmt=con.createStatement();
    ResultSet rs=stmt.executeQuery("select max(loc_id) from group1_location_master order by loc_id");

    int i=0;
    while(rs.next())
    {
    i=rs.getInt(1);
    i++;

    stmt.executeUpdate("insert into group1_location_master(loc_id,loc_name)values('"+i +"','"+loc+"')");
    System.out.println(loc);

    }

    ResultSet rs1=stmt.executeQuery("select max(quali_id) from group1_qualification_master");
    {
    stmt.executeUpdate("insert into group1_qualification_master(quali_id,degree)values ("+i+",'"+qul+"')");
    System.out.println(qul);
    }

    ResultSet rs2=stmt.executeQuery("select max(programming_id) from group1_program_skill_master");
    {
    stmt.executeUpdate("insert into group1_program_skill_master(programming_id,program ming_skill)values("+i+",'"+pro+"')");
    System.out.println(pro);
    }

    ResultSet rs3=stmt.executeQuery("select max(database_id) from group1_database_skill_master");
    {
    stmt.executeUpdate("insert into group1_database_skill_master(database_id,database_ skill)values('"+i+"','"+db+"')");
    System.out.println(db);
    }

    ResultSet rs4=stmt.executeQuery("select max(platform_id) from group1_platform_skill_master");
    {
    stmt.executeUpdate("insert into group1_platform_skill_master(platform_id,platform_ skill)values('"+i+"','"+plat+"')");
    System.out.println(plat);
    }



    %>


    --------------------------------------------------------------------------------------------

    guys the prob is whenever i am inserting a value the loc id is incrementand also insert...but...it show like that in all the table........plzz help me out....and send me da code where i m wrong....

    LOC_ID LOC_NAME
    ---------- -------------
    3 delhi
    4 mumbai
    1 kolkata
    2 chennai
    Last edited by shuvra_pan; 10-28-2008 at 08:10 PM.

  2. #2
    andy_man's Avatar
    andy_man is offline Member
    Join Date
    Oct 2008
    Location
    Yerevan
    Posts
    14
    Rep Power
    0

    Default

    Java Code:
    <%@page import="java.sql.*"%> 
    <%@page import="java.io.*"%>
    <%@include file="connection.jsp"%>
    <%
        try
    	{
    	   int n=0;
    	   String loc=request.getParameter("Location");
    	   String qul=request.getParameter("Qualification");
    	   String pro=request.getParameter("Programming");
    	   String db=request.getParameter("Database");
    	   String plat=request.getParameter("Platform");
    	   
    	    Statement stmt=con.createStatement();
    		 
    	    ResultSet rs=stmt.executeQuery("select * from group1_location_master");
    		
    		while(rs.next())
    				 {  
    				 stmt.executeUpdate("insert into group1_location_master(loc_id,loc_name)values('"+n+"','"+loc+"')");
    		System.out.println(n);  
    		System.out.println(loc);
                    n++; 
              }
       catch(exception e)
            {
               System.out.println(e);
             }
    Quote Originally Posted by shuvra_pan View Post


    --------------------------------------------------------------------------------------------------------
    guyz the moto of this prog is to increment the loc id whenever i will enter a location...
    the prob is whenever i am inserting a value the loc id is not changing......remains 1.

    plz help me out..........
    The first thing, when you are posting a code, you can use "CODE" tags, for making your code readable.
    The second, in your code I can see that you are incrementing "n" variable and not "loc" one. So loc, is the same as you've get it from request.
    TEAM = Together Everyone Achieves More :)

  3. #3
    nHulk's Avatar
    nHulk is offline Member
    Join Date
    Apr 2011
    Posts
    5
    Rep Power
    0

    Default

    try this !!!

    while(rs.next())
    {
    i=rs.getInt("max(loc_id)");
    i++;
    }

Similar Threads

  1. Restart a For loop and increment an Int value
    By dcnorman07 in forum New To Java
    Replies: 1
    Last Post: 07-12-2008, 12:24 AM
  2. Increment a Variable
    By rhm54 in forum New To Java
    Replies: 2
    Last Post: 06-14-2008, 02:57 AM
  3. for each prob
    By kusumathatavarthi in forum New To Java
    Replies: 7
    Last Post: 05-21-2008, 01:00 PM
  4. How to create auto-increment
    By Albert in forum JDBC
    Replies: 2
    Last Post: 07-04-2007, 05:23 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •