how to retrieve a checkbox value(retrieve from DB)

Ads
 

how to retrieve a checkbox value(retrieve from DB)

I facing a problem with checkbox value that already exists inside the database. so how can I retrieve those value from another database table? the table subject and service below is what I want. But based on the code below the SERVICE TABLE on SUBJECTID COLUMN producing null value. How to remove those null value with subjectid value? I don't understand that well because I am a newbie.

SUBJECT TABLE

SUBJECTID       SUBJECTNAME
-----------     ----------------
PT3_ENGLISH      ENGLISH
PT3_BM           BAHASA MELAYU
PT3_SC           SCIENCE
PT3_MATH         MATHEMATICS

CURRENT SERVICE TABLE IN DB

   SERVICE TABLE 
    SERVICEID       SERVICECATEGORY    SERVICETYPE     STUDENTID    SUBJECTID
    ---------       ---------------    -----------     ---------    ----------
    123             PT3                 ORDINARY       20345         null

TABLE THAT I WANT.

SERVICE TABLE 
SERVICEID       SERVICECATEGORY    SERVICETYPE     STUDENTID    SUBJECTID
---------       ---------------    -----------     ---------    ----------
123             PT3                 ORDINARY       20345         PT3_ENGLISH
                                                                 PT3_BM
                                                                 PT3_SC
                                                                 PT3_MATH

here my registration.jsp

<u><center><h2>Services Information </h2></center></u>
                                    <hr>
                                    </div>
                                    <br>


                                     <div class="one_third first">Service Type:
                                        <select name="servicetype" id="servicetype" required>
                                                <option value="">- Service Type -</option>
                                                <option value="ORDINARY">ORDINARY</option>
                                                <option value="PERMATA">PERMATA</option>
                                                <option value="PRIVATE">PRIVATE</option>
                                                <option value="PMC">PMC</option>
                                            </select>
                                        </div>


                                    <div class="one_half">Service Category:
                                        <select name="servicecategory" id="servicecategory" required>
                                                <option value="">-Service Category -</option>
                                                <option value="UPSR">UPSR</option>
                                                <option value="PT3">PT3</option>
                                                <option value="SPM">SPM</option>
                                            </select>
                                        </div>



                            <BR><BR><BR><h2>Subject</h2>
                             <div class="three_quarter first">  
                                        <h3>UPSR</h3>
                                         <input type="checkbox" class="dissable" onclick="check();" name="UPSR" value="UPSR_ENGLISH" id="subjectId">English </td>
                                </div>              
                            <br><br><hr><br><br>        
                             <div class="three_quarter first">  
                                  <h3>PT3</h3>
                                    <input type="checkbox" class="dissable" onclick="check();" name="PT3" value="PT3_ENGLISH" id="subjectId">English </td>
                                    <input type="checkbox" class="dissable" onclick="check();" name="PT3" value="PT3_BM" id="subjectId">Bahasa Melayu</td>
                                    <input type="checkbox" class="dissable" onclick="check();" name="PT3" value="PT3_SC" id="subjectId">Science</td>
                                    <input type="checkbox" class="dissable" onclick="check();" name="PT3" value="PT3_MATH" id="subjectId">Mathematics</td>
                            </div-->
                            <br><br><hr><br><br>
                             <div class="block clear">  
                                  <h3>SPM</h3>
                                     <input type="checkbox" class="dissable" onclick="check();" name="SPM" value="SPM_ENGLISH" id="subjectId">English </td> 
                                     <input type="checkbox" class="dissable" onclick="check();" name="SPM" value="SPM_BM" id="subjectId">Bahasa Melayu</td>
                                     <input type="checkbox" class="dissable" onclick="check();" name="SPM" value="SPM_SC" id="subjectId">Science</td>
                                     <input type="checkbox" class="dissable" onclick="check();" name="SPM" value="SPM_MATH" id="subjectId">Mathematics</td>
                                     <input type="checkbox" class="dissable" onclick="check();" name="SPM" value="SPM_ADDMATH" id="subjectId">Additional Mathematics </td>
                                     <input type="checkbox" class="dissable" onclick="check();" name="SPM" value="SPM_HISTORY" id="subjectId">History</td>
                                     <input type="checkbox" class="dissable" onclick="check();" name="SPM" value="SPM_ECONOMY" id="subjectId">Economy</td>
                                     <input type="checkbox" class="dissable" onclick="check();" name="SPM" value="SPM_PHYSIC" id="subjectId">Physics</td><br>
                                     <input type="checkbox" class="dissable" onclick="check();" name="SPM" value="SPM_CHEMISTRY" id="subjectId">Chemistry</td>
                                     <input type="checkbox" class="dissable" onclick="check();" name="SPM" value="SPM_BIOLOGY" id="subjectId">Biology</td>
                                     <input type="checkbox" class="dissable" onclick="check();" name="SPM" value="SPM_ACCOUNT" id="subjectId">Account</td>
                                </div>

here is my Servlet registerServlet.java

           String[] sv;
              String[] sv2;
              String[] sv3;

              sv = request.getParameterValues("UPSR");
              sv2 = request.getParameterValues("PT3");
              sv3 = request.getParameterValues("SPM");
              String subjectId= "";                 //first declare the variable to store the value to store loop value
              String service = request.getParameter("servicecategory"); // retrieve parameter value
                                                                        // int i=0; declare variable for loop
               if(service.equalsIgnoreCase("UPSR")){

                   for(int i = 0; i <sv.length; i++){       // for loop to read one by one all the checkbox checked status
                       if(i<sv.length-1){
                           subjectId = subjectId +sv[i]+ ","; //store value of checked checkbox
                       }
                       else{
                           subjectId = subjectId + sv[i];
                       }
                   }

               }
               else if(service.equalsIgnoreCase("PT3")){

                   for(int i = 0; i <sv2.length; i++){
                       if(i<sv2.length-1){
                           subjectId = subjectId +sv2[i]+ ",";
                       }
                       else{
                           subjectId = subjectId + sv2[i];
                       }
                   }

               }
               else if(service.equalsIgnoreCase("SPM")){

                   for(int i = 0; i <sv3.length; i++){
                       if(i<sv3.length-1){
                           subjectId = subjectId +sv3[i]+ ",";
                       }
                       else{
                           subjectId = subjectId + sv3[i];
                       }
                   }

               }


               svb.setServiceid(request.getParameter("serviceid"));
               svb.setStudentid(request.getParameter("studentid"));
               svb.setServicecategory(service);
               svb.setServicetype(request.getParameter("servicetype"));

               sub.setSubjectId(subjectId);
               sub.setSubjectName(request.getParameter("subjectName"));

               System.out.println(service);

               sb = RegisterDAO.registerStudent(sb);
               svb = RegisterDAO.registerService(svb);
               sub = RegisterDAO.registerSubject(sub);

last is my registerDAO.java containing a certain part of registration subject only

//registersubject
            public static SubjectBean registerSubject(SubjectBean bean) { // preparing some objects for connection 
                System.out.println("JIJIJI SUBJECT"); 
                Statement stmt = null; 

                String subjectId = bean.getSubjectId(); 
                String searchQuery = "select * from subject where subjectId='" + subjectId +"'";

                //String query = "select * from SUBJECT where ROWNUM <=1 ORDER BY SUBJECTID DESC";

                // "System.out.println" prints in the console; Normally used to trace the process 
                System.out.println("Your subject ID is " + subjectId); 
                //System.out.println("Your subject name is " + subjectName); 
                System.out.println("Query: " + searchQuery); 

                try { // connect to DB 
                    currentCon = connectionManager.getConnection(); 
                    stmt = currentCon.createStatement(); 
                    rs = stmt.executeQuery(searchQuery);
                    boolean more = rs.next(); 


                    subjectId=rs2.getString("subjectId");

                    System.out.println("\n the subject are : "+subjectId);

                    bean.setValid(true);
                    bean.setSubjectId(subjectId);
                    bean.setSubjectName(rs2.getString("subjectName"));


                    // if subject does not exist set the isValid variable to false 
                    if (!more) { 
                        System.out.println("Sorry, no subject registered! Please ask the clerk first"); 
                        bean.setValid(false); 
                        } 
                    // if user exists set the isValid variable to true 
                    //else if (more) { 

                        //System.out.println("Added Subject!"); 

                        //System.out.print("3");
                        //stmt.executeUpdate(searchQuery);
                        //System.out.print("4");
                        //System.out.print("1 new row inserted in table subject");

                        //bean.setValid(true); 
                        //} 
                    } 
                catch (Exception ex) { 
                    System.out.println("Log In failed: An Exception has occurred! " + ex); 
                    } 
                // some exception handling 
                finally { 
                    if (rs != null) { 
                        try { rs.close(); 
                        } 
                            catch (Exception e) {   
                            } 
                            rs = null; 
                        } 
                    if (stmt != null) { 
                        try { stmt.close(); 
                        } 
                            catch (Exception e) { 

                            } 
                            stmt = null; 
                            } 

                    if (currentCon != null) {
                        try { currentCon.close();
                        } 
                        catch (Exception e) { 

                        } 
                        currentCon = null; 
                        } 
                    } 
                return bean;

Please help me. thanks in advance.

View Answers

Ads









Related Tutorials/Questions & Answers:
how to retrieve a checkbox value(retrieve from DB)
how to retrieve a checkbox value(retrieve from DB)   I facing a problem with checkbox value that already exists inside the database. so how can I retrieve those value from another database table? the table subject and service
how to insert, retrieve data from,to db(code)....
how to insert, retrieve data from,to db(code)....  Hi..... i ve... that data will b stored in db(m using sybase). 2.also hw to retrieve the data from db. cn u plz tel me the code in detail.n i thk it shud b written in jdbc
Advertisements
retrieve value from db in text box + calendar implementation.
retrieve value from db in text box + calendar implementation.  I... there is already a text box..Now i want to get the value retrieved from database in that text field how can i do it... Please help...   Please visit
how to insert, retrieve data from,to db(code)....
how to insert, retrieve data from,to db(code)....  Hi, i have created login page n in that a registration form also in jsp, my doubt is-when new user... will b stored in db(m using sybase). 2.also hw to retrieve the data from db. cn u
how to retrieve data from database ?????/
how to retrieve data from database ?????/  how to retrieve data from database
how to retrieve data from database ?????/
how to retrieve data from database ?????/  how to retrieve data from database
how to retrieve data from database ?????/
how to retrieve data from database ?????/  how to retrieve data from database
how to retrieve data from database ?????/
how to retrieve data from database ?????/  how to retrieve data from database
how to retrieve data from database
how to retrieve data from database  unable to retrieve data from database using mySQL by using jsp sessions and beans for editing
How to retrieve record from table
How to retrieve record from table  Hi. I have a field in database...,kanchipuram for a single record. I have to retrieve these data from the field table... like chennai as one value, trichy as one value. and i have to show it in html
how to get the checkbox value in jsp
how to get the checkbox value in jsp  how to get the checkbox value in jsp?   JSP CheckBox Example - how to get the checkbox value in jsp
How to retrieve image from database
How to retrieve image from database  hi........ How to retrieve image from database when it is stored. I have stored image in postgresql and want to retrieve in java form. Can u tel me hw to do? I am trying n able to do also
how to retrieve the id value itself from the access database to drop down listbox in jsp
how to retrieve the id value itself from the access database to drop down listbox in jsp  how to retrieves the id which is an int datatype, from...   <%@page import="java.sql.*"%> <select> <option value
Retrieve value of radio button from database to form
Retrieve value of radio button from database to form  var gn=document.getElementsByName("empg"); //empg is name of radio input type. for(var i=0;i
How to change the checkbox value dynamically.
How to change the checkbox value dynamically.  Hi, I am using struts 1.2 checkbox tag. Requirement is on page load the value must be "true... the page. Then the checkbox is checked instead it have to show unchecked. And even
How to store two integer value in a separate file and retrieve those values
How to store two integer value in a separate file and retrieve those.... But Don't have any idea how can i do that. Like what format of file i need, or how can i write and update value in that file
How to retrieve data by using combo box value in jsp? - JSP-Servlet
How to retrieve data by using combo box value in jsp?  Hi Friends, When i click combobox value in jsp form page, it will diplay related value.... I am using only this page.. not get value from another page
how to use bean to retrieve data from database
how to use bean to retrieve data from database  how to use bean to retrieve data from database   poda sendru
How to retrieve image from database in Servlet?
How to retrieve image from database in Servlet?  Hi, How to retrieve image from database in Servlet? Thanks   Hi, Please check the tutorial Retrieve image from database using Servlet. Thanks
How to Retrieve Data from Facebook Using PHP
How to Retrieve Data from Facebook Using PHP  is this link has right content regards that?? http://techpdf.co.cc/blog/how-to-retrieve-data-from-facebook-using-php
How to Retrieve Data from Facebook Using PHP
How to Retrieve Data from Facebook Using PHP  is this link has right content regards that?? http://techpdf.co.cc/blog/how-to-retrieve-data-from-facebook-using-php
How to retrieve and display image from database in Java?
How to retrieve and display image from database in Java?  Hi, I am.... Please check the it at How to store and retrieve image from database in JSP... on the web page. My application is in Java/JSP. How to retrieve and display image
How to retrieve blob image from database in JSP?
How to retrieve blob image from database in JSP?  Hello, JSP is used... the blog image from database. How to retrieve blob image from database in JSP?   Hi, Please check the tutorial Retrieve image from database using
retrieve value from database on the basis of maximum id number
retrieve value from database on the basis of maximum id number  hi, i want to retrieve value of maximum id number from the database and show that value in jTextField.when the user clicks on the button that maximum id number
How to store and retrieve image from database in JSP?
How to store and retrieve image from database in JSP?  Hi, In one... and retrieve image from database in JSP? Thanks   HI, You can use... the image. Check this example: Retrieve image from database using Servlet. Thanks
How to retrieve image from mysql database in JSP?
How to retrieve image from mysql database in JSP?  Hi, I need JSP same codes for learning to get image which is stored in MySQL Database. How to retrieve image from mysql database in JSP? Thanks   Hi, You can write
How to retrieve a field from SQLite to Edittext in android
How to retrieve a field from SQLite to Edittext in android  Hi... Im new to android.. i do no how to retrieve a field from database(SQLite). I'd like to retrieve password field to my edittext in my app.. This is my code
How to retrieve a field from SQLite to Edittext in android
How to retrieve a field from SQLite to Edittext in android  Hi... Im new to android.. i do no how to retrieve a field from database(SQLite). I'd like to retrieve password field to my edittext in my app.. This is my code
retrieve the data to text fields from database on clicking the value of combo box
retrieve the data to text fields from database on clicking the value of combo box   retrieve the data to text fields from database on clicking the value of combo box . I am not getting it plz help me out .   hi
how to store and retrieve image from database
how to store and retrieve image from database  how to store and retrieve images into database(oracle) and how to retrive images from database using jsp   Here is a jsp code that insert and retrieve image from mysql
how to insert checkbox value into database using jsp
how to insert checkbox value into database using jsp  How to insert...;input name="activity7" type="checkbox" id="act_name" name="act_name" value... <input name="activity" type="checkbox" id="act_name" name="act_name" value

Ads