Jdbc

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shanmukhi
    New Member
    • Jan 2007
    • 58

    #1

    Jdbc

    hi,

    This is one of the column in my database table.
    ID is primary column

    CITY ID

    Colway
    Colway ---row 2 00232
    Colway
    Colway
    Colway
    Colway 1
    ColPOP
    Colway 2
    ColPOP
    Colway 2
    ColPOP
    ColPOP
    Colway 1
    Colway 3
    Colway 1---row 15 00275
    Colway
    Colway 1
    Colway 2
    ColPOP
    Colway 1
    Colway 1
    Colway
    Colway
    Colway
    Colway
    Shakti Nagar HLR

    i want to display only 2nd and 15th row values
    how can i write jdbc code to retrieve it


    i took two result sets to retrieve it...and im differenciating by primary key ID
    iam not getting any idea of doing with single result set
    can anybody tell me easy code for it..
    Code:
    Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
    				ResultSet.CONCUR_READ_ONLY);
    				Statement stmt1 = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
    						ResultSet.CONCUR_READ_ONLY);
    				ResultSet rs=stmt.executeQuery("select *  from CITY where city='Colway'and ID='00232'");
    				ResultSet rs1=stmt1.executeQuery("select *  from CITY where city='Colway 1'and ID='00275'");
    				
    
    				while(rs.next())
    				{
    			System.out.println("connecting to database");
    			String ct=rs.getString("CITY");
    		       	System.out.println(ct);
    			 		
    			break;
    			}
    	 		       while(rs1.next())
    	 		      {
    	 		String ct=rs1.getString("CITY");
            	       	System.out.println(ct);
    		 
    			break;
    	 			}
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by shanmukhi
    hi,

    This is one of the column in my database table.
    ID is primary column

    CITY ID

    Colway
    Colway ---row 2 00232
    Colway
    Colway
    Colway
    Colway 1
    ColPOP
    Colway 2
    ColPOP
    Colway 2
    ColPOP
    ColPOP
    Colway 1
    Colway 3
    Colway 1---row 15 00275
    Colway
    Colway 1
    Colway 2
    ColPOP
    Colway 1
    Colway 1
    Colway
    Colway
    Colway
    Colway
    Shakti Nagar HLR

    i want to display only 2nd and 15th row values
    how can i write jdbc code to retrieve it


    i took two result sets to retrieve it...and im differenciating by primary key ID
    iam not getting any idea of doing with single result set
    can anybody tell me easy code for it..
    Code:
     
    Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
    				ResultSet.CONCUR_READ_ONLY);
    				Statement stmt1 = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
    						ResultSet.CONCUR_READ_ONLY);
    				ResultSet rs=stmt.executeQuery("select * from CITY where city='Colway'and ID='00232'");
    				ResultSet rs1=stmt1.executeQuery("select * from CITY where city='Colway 1'and ID='00275'");
     
     
    				while(rs.next())
    				{
    			System.out.println("connecting to database");
    			String ct=rs.getString("CITY");
    			 System.out.println(ct);
     
    			break;
    			}
    			  while(rs1.next())
    			  {
    			 String ct=rs1.getString("CITY");
    		 System.out.println(ct);
     
    			break;
    				 }
    Is there anything unique about those two rows. Remember you cannot guarantee the order of rows in a database. To perform a query you need to identify something about the rows of data that you want to extract.

    Comment

    • shanmukhi
      New Member
      • Jan 2007
      • 58

      #3
      Originally posted by r035198x
      Is there anything unique about those two rows. Remember you cannot guarantee the order of rows in a database. To perform a query you need to identify something about the rows of data that you want to extract.
      i did nt get you what you are telling....

      i specified two colums there
      one is ID that is unique for table...
      my required data is in CITY column...
      suppose if i dnt have repeated data in CITY coumn then how can i retrieve data..
      i.e only 2nd and 15th row

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by shanmukhi
        i did nt get you what you are telling....

        i specified two colums there
        one is ID that is unique for table...
        my required data is in CITY column...
        suppose if i dnt have repeated data in CITY coumn then how can i retrieve data..
        i.e only 2nd and 15th row
        If you know the ids for these columns then you can use a select statement that selects rows for the ids.

        Comment

        • shanmukhi
          New Member
          • Jan 2007
          • 58

          #5
          Originally posted by r035198x
          If you know the ids for these columns then you can use a select statement that selects rows for the ids.
          ok..
          suppose i have unique column values
          then how can i retrieve only a specific row

          Comment

          • r035198x
            MVP
            • Sep 2006
            • 13225

            #6
            Originally posted by shanmukhi
            ok..
            suppose i have unique column values
            then how can i retrieve only a specific row
            I have a much better idea. Here are links to a jdbc and an sql tutorial

            Comment

            • shanmukhi
              New Member
              • Jan 2007
              • 58

              #7
              Originally posted by r035198x
              I have a much better idea. Here are links to a jdbc and an sql tutorial

              ok thank you for ur reply

              Comment

              Working...