Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Java
  4. ResultSet to Int [modified]

ResultSet to Int [modified]

Scheduled Pinned Locked Moved Java
databasequestiondebugginghelptutorial
7 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    pancakeleh
    wrote on last edited by
    #1

    How to convert ResultSet to Integer? i do it this way however i encountered errors. codes as follows:

     rs = stmt.executeQuery("Select count(1) from INCIDENTDATA where INCIDENTID = 10");
    
     Integer id = rs.getInt(1);
    
        if( id == 0){
          .
          .
          .
          }
    

    When i do a debug errors i encounted: 1. "id" is not a known variable in the current context.; 2. "rs" is not a known variable in the current context.; http://img841.imageshack.us/img841/1965/exeerror.png[^] needing help. When i execute the SQL this is the screen shot : http://img502.imageshack.us/img502/8532/executey.png[^] how do i get the value 0 so as to compare it if it is 0 then i will add the value 10 into the database?

    modified on Sunday, January 16, 2011 11:25 PM

    P 1 Reply Last reply
    0
    • P pancakeleh

      How to convert ResultSet to Integer? i do it this way however i encountered errors. codes as follows:

       rs = stmt.executeQuery("Select count(1) from INCIDENTDATA where INCIDENTID = 10");
      
       Integer id = rs.getInt(1);
      
          if( id == 0){
            .
            .
            .
            }
      

      When i do a debug errors i encounted: 1. "id" is not a known variable in the current context.; 2. "rs" is not a known variable in the current context.; http://img841.imageshack.us/img841/1965/exeerror.png[^] needing help. When i execute the SQL this is the screen shot : http://img502.imageshack.us/img502/8532/executey.png[^] how do i get the value 0 so as to compare it if it is 0 then i will add the value 10 into the database?

      modified on Sunday, January 16, 2011 11:25 PM

      P Offline
      P Offline
      pancakeleh
      wrote on last edited by
      #2

      I have made changes to the codes. Right now i dont face any error but however i dont see the value that i have added, being added to the table.

      public String add_btn_action() throws SQLException {
      ResultSet rs = null;
      Statement stmt = null;

          Integer id;
          String dbURL = "....";
      
          String incidentId = (String) getIncidentidtxt().getValue();
          Integer incidentIntId = Integer.parseInt(incidentId);
          String incidentName = (String) getIncidentnametxt().getValue();
      
          Connection con = DriverManager.getConnection(dbURL);
      
          try{
      
               stmt = con.createStatement();
      
               rs = stmt.executeQuery("Select COUNT(1) from INCIDENTDATA where INCIDENTID = "+incidentIntId+"");
      
               while(rs.next()){
      
               id = rs.getInt(1);
      
            
               if( id == 0){
      
              getSessionBean1().updateIncident(incidentIntId, incidentName);
              incidentdataDataProvider.refresh();
               }
      
                else{
      
          Integer newIncidentID =  incidentIntId + 1;
      
          getSessionBean1().updateIncident(newIncidentID, incidentName);
          instancedataDataProvider.refresh();
          }
               }
      
      }
      catch(Exception e){
          e.getMessage();
      }
          
          return null;
      }
      

      Needing help..

      D J 2 Replies Last reply
      0
      • P pancakeleh

        I have made changes to the codes. Right now i dont face any error but however i dont see the value that i have added, being added to the table.

        public String add_btn_action() throws SQLException {
        ResultSet rs = null;
        Statement stmt = null;

            Integer id;
            String dbURL = "....";
        
            String incidentId = (String) getIncidentidtxt().getValue();
            Integer incidentIntId = Integer.parseInt(incidentId);
            String incidentName = (String) getIncidentnametxt().getValue();
        
            Connection con = DriverManager.getConnection(dbURL);
        
            try{
        
                 stmt = con.createStatement();
        
                 rs = stmt.executeQuery("Select COUNT(1) from INCIDENTDATA where INCIDENTID = "+incidentIntId+"");
        
                 while(rs.next()){
        
                 id = rs.getInt(1);
        
              
                 if( id == 0){
        
                getSessionBean1().updateIncident(incidentIntId, incidentName);
                incidentdataDataProvider.refresh();
                 }
        
                  else{
        
            Integer newIncidentID =  incidentIntId + 1;
        
            getSessionBean1().updateIncident(newIncidentID, incidentName);
            instancedataDataProvider.refresh();
            }
                 }
        
        }
        catch(Exception e){
            e.getMessage();
        }
            
            return null;
        }
        

        Needing help..

        D Offline
        D Offline
        David Skelly
        wrote on last edited by
        #3

        A good place to start would be with the on-line JDBC tutorials: http://java.sun.com/products/jdbc/learning.html[^] http://download.oracle.com/javase/tutorial/jdbc/index.html[^]

        L 1 Reply Last reply
        0
        • D David Skelly

          A good place to start would be with the on-line JDBC tutorials: http://java.sun.com/products/jdbc/learning.html[^] http://download.oracle.com/javase/tutorial/jdbc/index.html[^]

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          I wish I had £1 for every time I suggested the OP spend some time studying this subject.

          I must get a clever new signature for 2011.

          1 Reply Last reply
          0
          • P pancakeleh

            I have made changes to the codes. Right now i dont face any error but however i dont see the value that i have added, being added to the table.

            public String add_btn_action() throws SQLException {
            ResultSet rs = null;
            Statement stmt = null;

                Integer id;
                String dbURL = "....";
            
                String incidentId = (String) getIncidentidtxt().getValue();
                Integer incidentIntId = Integer.parseInt(incidentId);
                String incidentName = (String) getIncidentnametxt().getValue();
            
                Connection con = DriverManager.getConnection(dbURL);
            
                try{
            
                     stmt = con.createStatement();
            
                     rs = stmt.executeQuery("Select COUNT(1) from INCIDENTDATA where INCIDENTID = "+incidentIntId+"");
            
                     while(rs.next()){
            
                     id = rs.getInt(1);
            
                  
                     if( id == 0){
            
                    getSessionBean1().updateIncident(incidentIntId, incidentName);
                    incidentdataDataProvider.refresh();
                     }
            
                      else{
            
                Integer newIncidentID =  incidentIntId + 1;
            
                getSessionBean1().updateIncident(newIncidentID, incidentName);
                instancedataDataProvider.refresh();
                }
                     }
            
            }
            catch(Exception e){
                e.getMessage();
            }
                
                return null;
            }
            

            Needing help..

            J Offline
            J Offline
            jschell
            wrote on last edited by
            #5

            pancakeleh wrote:

            Right now i dont face any error but however i dont see the value that i have added, being added to the table.

            You would of course need to write code that does in fact do an update to the table.

            P 1 Reply Last reply
            0
            • J jschell

              pancakeleh wrote:

              Right now i dont face any error but however i dont see the value that i have added, being added to the table.

              You would of course need to write code that does in fact do an update to the table.

              P Offline
              P Offline
              pancakeleh
              wrote on last edited by
              #6

              I have written a method in sessionBean named updateIncident for adding the values to the database. the codes as follows:

              public void updateIncident(Integer incidentIDName, String incidentNameName){
              
                  incidentdataDataProvider.refresh();
              
                  //Set new row
                  RowKey rkUpdate = incidentedataDataProvider.appendRow();
              
                  //Move to new created row
                  incidentdataDataProvider.setCursorRow(rkUpdate);
              
                  //Set Input
                   incidentdataDataProvider.setValue("INCIDENTDATA.INCIDENTID", incidentIDName);
                   incidentdataDataProvider.setValue ("INCIDENTDATA.INCIDENTNAME", incidentNameName);
              
                 incidentdataDataProvider.refresh();
              
              }
              
              K 1 Reply Last reply
              0
              • P pancakeleh

                I have written a method in sessionBean named updateIncident for adding the values to the database. the codes as follows:

                public void updateIncident(Integer incidentIDName, String incidentNameName){
                
                    incidentdataDataProvider.refresh();
                
                    //Set new row
                    RowKey rkUpdate = incidentedataDataProvider.appendRow();
                
                    //Move to new created row
                    incidentdataDataProvider.setCursorRow(rkUpdate);
                
                    //Set Input
                     incidentdataDataProvider.setValue("INCIDENTDATA.INCIDENTID", incidentIDName);
                     incidentdataDataProvider.setValue ("INCIDENTDATA.INCIDENTNAME", incidentNameName);
                
                   incidentdataDataProvider.refresh();
                
                }
                
                K Offline
                K Offline
                Khalil Adam
                wrote on last edited by
                #7

                thanks but where should u put all this code(mean to put it inside the try and catch or where...)

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups