Doubt in JSP recordset

Hi i have a doubt in jsp...first i don know much abt jsp so iam gonna trying out a project on supermarket system.Here i have three tables Items,Bill and Report.Iam using three resultset continuously and i have error saying no resultset found.I have sent the code can anyone plz help me correcting it.
<%
String item= request.getParameter("itemadd");
String qr=request.getParameter("quanreq");
HttpSession Dsess=request.getSession();
String refer = (String)Dsess.getAttribute("user");
Date dd = new Date();
SimpleDateFormat sdf1 = new SimpleDateFormat("dd");
String date = sdf1.format(dd);
Date mm = new Date();
out.println(date);
SimpleDateFormat sdf2 = new SimpleDateFormat("MMM");
String mon = sdf2.format(mm);
Date yy = new Date();
SimpleDateFormat sdf3 = new SimpleDateFormat("yyyy");
String year = sdf3.format(yy);
try
     Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
     Connection con=DriverManager.getConnection("jdbc:odbc:honeydew"," "," ");
     Statement st= con.createStatement();
     ResultSet rs = st.executeQuery("Select * from Items where Iname = '"+item+"' ");
     String uni = new String();
     String pri = new String();
     while(rs.next())
          uni = rs.getString(4);
          pri = rs.getString(5);
     ResultSet rs4 = st.executeQuery("update Items set Quantity = Quantity - '"+qr+"' where Iname ='"+item+"' ");
     ResultSet rs2 = st.executeQuery("insert into Bill values('"+item+"','"+qr+"','"+uni+"','"+pri+"','"+refer+"')");
     ResultSet rs2 = st.executeQuery("insert into Report values('"+item+"','"+qr+"','"+uni+"','"+pri+"','"+date+"','"+mon+"','"+year+"')");
catch(Exception e)
%>
<html>
<body bgcolor="#CCDDEF">
<%@ page import = "java.sql.*" %>
<%@ page import = "java.lang.*" %>
<%@ page import = "java.util.Date" %>
<%@ page import = "java.text.*" %>

Hi
When you are doing either update or insert database operations, use Statement.executeUpdate("insert . . . . "), which will return how many rows are effected. So instead of
ResultSet rs1 = stmt.executeQuery("update ......"); use the following
stmt.excuteUpdate("update ...... ");

Similar Messages

  • Help me -doubt in jsp

    hai
    In my jsp page one checkbox is there.
    when i check the checkbox then another on textarea will popup
    and vice versa
    plese help me
    it is very urgent
    thank you

    * dont doubt JSP it has proven its worth.
    * checking checkbox and hidding/showing textareas is not in your JSP but in the HTML that is send to your client by making a request to your JSP, its a detail but a very important one
    * This means you need Javascript that will change the style of yor HTML components, have a look at a javascript onclick or onchange events and at the DOM model.
    * example
    yourtextarea.style.visibility = 'hidden'

  • Doubt in JSP

    hi ,
    i was new to JSP, when iam learning jsp, i worte a jsp file for performing session tracking using jsp:usebean tag , for that i create a bean and i generate a class and i put that class in classes folder.
    here i got a problem, when i call this in browser i got an error...... class not found. after trying 3 to 4 times i got the same error. i dont know why the error. i wrote all the code correctly and i deploy my application perfectly.
    after that i got an idea to put that class in a package now i got the result without any error.
    Why did we create a new package to perform beans????????

    There's no doubt in my mind you are correct. :)
    Or did I just prove you wrong beyond a doubt? ;)
    Neither. He used the construct "to have a doubt" as a verb, which is incorrect as the word can't be used like that.
    Of course even if it could the very meaning of the word is quite different from the intended "question" as "doubt" doesn't mean question at all but rather "reservation" (and no, that's not a reservation to a theater seat or restaurant table).

  • Simple Doubt in JSP

    I have a set of check boxes and corresponding text boxes in a HTML form. I want to display the text box value if the corresponding check box is checked.
    Can anybody tell me how to accomplish this?

    I have a set of check boxes and corresponding text
    boxes in a HTML form. I want to display the text box
    value if the corresponding check box is checked.
    Can anybody tell me how to accomplish this?when are you trying to display the text box value? After they hit a submit button or something? If thats true then you can if you want write a servlet or jsp which will handle the POST action. Then you can get the value depending on what you named it in them in the JSP.
    So if you named your field something like:
    <input type="text" name="text_one"/><input type="checkbox" name="mycheckbox" value="one"><br>
    <input type="text" name="text_two"/><input type="checkbox" name="mycheckbox" value="two"><br>
    <input type="text" name="text_three"/><input type="checkbox" name="mycheckbox" value="three"><br>
    Now you can do:
    String[] checkBoxValues = request.getParameterValues("mycheckbox");
    for(int i = 0; i < checkBoxValues.length; i++) {
    if(checkBoxValues.equals("one"))
    System.out.println(request.getParameter("text_one");
    else if(checkBoxValues[i].equals("two"))
    System.out.println(request.getParameter("text_two");
    else if(checkBoxValues[i].equals("three"))
    System.out.println(request.getParameter("text_three");
    Obviously there probably way better ways to do this but this should at least lead you in the right direction.
    -Chuy

  • Doubt in jsp or oracle

    hi everyone,
              i'm working with a jsp code which uses oracle as backend i come across
              a statement like this
              rs2=st2.executeQuery("select name from emp where ecode='"+ecode+"'");
              what the + mean in --"+ecode+"
              is it related to jsp or oracle,
              help me in bebuging the code
              

              That is from your JSP, "ecode" in ecode is a variable in your JSP.
              [email protected] (kasi) wrote:
              >hi everyone,
              >i'm working with a jsp code which uses oracle as backend i come across
              > a statement like this
              >
              >rs2=st2.executeQuery("select name from emp where ecode='"+ecode+"'");
              >
              >what the + mean in --"+ecode+"
              >is it related to jsp or oracle,
              >help me in bebuging the code
              

  • IN JSp : How to validate textbox of same name?

    Hi..
    Im having doubt in jsp & its urgent need for me..help out...
    Im having multiple html textbox of same name. Onclicking that textbox
    i have to call one JS page that creates calendar window which returns date
    to same textbox after selection.
    For single textbox, the values returns corretly..for multiple it doesnt return
    the value..coz of same name i think..
    Code:
    <script language="JavaScript" src="CmJavaScript.JS" ></script>
    <td class="table-text-tab"><input type=text name=a_date onClick=javascript:showcal('testForm.this.value'); value=<%=rs0.getString(5)%> size=13>
    <td class="table-text-tab"><input type=text name=f_date onClick=javascript:showcal('testForm.this.value'); value=<%=rs0.getString(7)%> size=13>
    Here showcal is the functionname & testform is the form name.
    here this two table data will be looped till the end of record selection.
    for example if i select 2 records in previous page..this code will be executed twice & will display textbox twice with same name..
    ie
    a_date ------------ f_date -----------
    a_date ------------ f_date -----------
    if i click first a_date textbox it populates calendar thru JS which returns date.
    bcoz of same textbox name..it doesnt returns the value...
    i mean its confused where to return whether in 1st (r) 2nd textbox?

    The same rule applies for textboxes as for checkboxes with the same name - indeed for any components accessed in the dom via javascript.
    If there is only one element of that name, it is accessed directly.
    If there is more than one element of that name, it reveals them as an array.
    so document.testForm.a_date would return an array of input fiels
    document.testForm.a_date[0], document.testForm.a_date[1] ... document.testForm.a_date[n]
    However the order of submission of parameters is NOT guarunteed, which is why people normally DON'T have fields in this manner - because you can't know for certain that a_date[1] matches with b_date[1] at the server end.
    The common practice is to give each field a unique name (numbered).

  • Can we include a JSP page in an already included JSP Page

    Hi guys,
    I have a doubt with JSP include tag. The problem is ..
    Can we include a JSP page in an already included JSP Page
    AS shown below
    I have one JSP page
    Index.jsp
    -in this I am including "include.jsp"
    -Again within the "include.jsp" I am including "include1.jsp"
    It is neither giving an error nor displaying the content which is there in the "include1.jsp" but it is displaying the content of "include.jsp"
    first of all let me know whether it is possible or no.. If so then why is it not coming and what is required to do this..
    fast...
    Thanks
    Sreenadha Reddy K

    Hi guys,
    I have a doubt with JSP include tag. The
    g. The problem is ..
    Can we include a JSP page in an already included JSP
    Page
    AS shown below
    I have one JSP page
    Index.jsp
    -in this I am including "include.jsp"
    -Again within the "include.jsp" I
    he "include.jsp" I am including "include1.jsp"
    It is neither giving an error nor displaying the
    content which is there in the "include1.jsp" but it is
    displaying the content of "include.jsp"
    first of all let me know whether it is possible or
    no.. If so then why is it not coming and what is
    required to do this..
    fast...
    Thanks
    Sreenadha Reddy KIt is possible , u just have to change all the files and save them all again, clear the temp dirs where all the jsp's as compiled. Now after all this try , it should work .

  • How to send query string by using form action

    Hai to all,
    I am new to this topic Ihave one doubt about jsp form action....
    That is I am using input type is submit button
    <input type="submit" name="submit" value="Edit" onclick="indows.location.href=+sample.jsp?query=+editvalue+editname">
    If I get that queryString in the sample.jsp page it respoce to the null only...... what is the problem to this code ..... please send ur perfect coding as soon as possible. I really waiting for ur replay..........

    Hai,
    I think u can use the "request.getQueryString()" to get the query string instead of using "request.getParameter()".
    From the query string value u can get the output.
    cheers,
    Redrose

  • How to refer javascript in servlets

    Hi friends,
    I have a doubt.In jsp we can use<%@ include file="sample.js"%>.How do you do the same operation in Servlets

    hey,
    first of all i would think about getRequestDispatcher().include(request,response), but at least at tomcat it works with .jsp files only (even html files can't be included...).
    so i guess the only way out you have is the annoying
    out.print(all_your_js_code_here)...

  • Validation of variable groups

    hi any1 pls help...
    how do i validate a jsp form which has example "x" textboxes with same name of choice<%=i%> and when i increase "i" i have another group of choices with another set of same names called
    choice<%=i+1%>
    i try using the code below but it doesnt work
    var d=0;
    for(var d=0;d< <%=i%>; d++){
    for (var h= 0; h < document.example.choices(d+1).length; h++) {
    var val2 = eval("document.example.choices[h]" +(d+1) + ".value");
    if (val2 == ""){
    alert("please fill in all the blanks.");
    return false; }
    }

    Hi..
    Im having doubt in jsp & its urgent need for me..help out...
    Im having multiple html textbox of same name. Onclicking that textbox
    i have to call one JS page that creates calendar window which returns date
    to same textbox after selection.
    For single textbox, the values returns corretly..for multiple it doesnt return
    the value..coz of same name i think..
    Code:
    <script language="JavaScript" src="CmJavaScript.JS" ></script>
    <td class="table-text-tab"><input type=text name=a_date onClick=javascript:showcal('testForm.this.value'); value=<%=rs0.getString(5)%> size=13>
    <td class="table-text-tab"><input type=text name=f_date onClick=javascript:showcal('testForm.this.value'); value=<%=rs0.getString(7)%> size=13>
    Here showcal is the functionname & testform is the form name.
    here this two table data will be looped till the end of record selection.
    for example if i select 2 records in previous page..this code will be executed twice & will display textbox twice with same name..
    ie
    a_date ------------ f_date -----------
    a_date ------------ f_date -----------
    if i click first a_date textbox it populates calendar thru JS which returns date.
    bcoz of same textbox name..it doesnt returns the value...
    i mean its confused where to return whether in 1st (r) 2nd textbox?

  • Tracking Link click

    Hi everyone!
    I have one doubt in JSP....
    I am having one JSP page (say Home page) which consists various url links(with a href tag).
    After clicking on to any of the links I want to keep the record of which link was clicked(i.e. which JSP page is called)
    I want to test it on home page itself instead of going into each JSP page to check which JSP was called everytime when user click on the available url on Home page.
    In short I want to track which reference link was clicked on Home page itself.
    Thanks & Regards
    Ketan.

    hi
    thanks for the reply...
    but I am trying to avoid modifying each jsp...
    so what I have decided is to write a javascript function in the Home JSP page itself which will take the url as an argument and is called when clicked on any of the link. In that function I am calling a Servlet with query string consisting of corresponding url.The sevlet will take care of storing the url in to the database as well as redirecting to that page.
    I have to follow the MVC architecture, so cant include files in JSPs to achieve the same.Instead , I am calling a Servlet which will work as a Controller.
    Thanks & Regards,
    Ketan

  • Best practice for dealing with Recordsets, JDBC and JSP?

    I've spent the last three years developing web apps using JSP, Struts and Kodo JDO for persistence. All of the content for the apps was created as Java objects using model classes and saved to an Oracle db. Thus, data retrieved from the db was as instances of the model classes and then put into Struts form beans, etc.
    I changed jobs last month and am now having to use Servlets with JDBC to retrieve records from db tables and returning it into Recordsets. Oh, and I can't use Struts in my JSPs either. I'm beginning to think that I had it easy at my previous job but maybe that's just because I was used to it.
    So here are my problems/questions:
    I have two tables with a one to many relationship that I need to retrieve data from, show in a jsp and be able to update eventually.
    So here's what I am doing:
    a) In a servlet, I use a SQL statement to join the tables and retrieve the results into a Recordset.
    b) I created a class with a bunch of String attributes to copy the Recordset data into, one Recordset row per each instance of the bean and then close the Recordset
    c) I then add the beans to an ArrayList and save the ArrayList into the session.
    d) Then, in the JSP, I retrieve the ArrayList from the session and iterate over each bean instance, printing the data out to the jsp. There are some logic statements to determine when not to print redundant data caused by the one to many join.
    e) I have not written the code to update the data yet but was planning on having separate jsps for updating the (one) table and the (many) table.
    Would most of you do something similar? Would you use one SQL statement to retrieve all of the data for display and use logic to avoid printing the redundant part of the data? Or would you have used separate SQL queries, one for each table? Would you have saved the results into something other than an instance of a bean class that represents one record in the RecordSet? Would you have had a bean class with attributes other than Strings - like had a collection attribute to hold the results from the "many" table? The way that I am doing everything just seems so cumbersome and difficult compared to using Struts and JDO before.
    Your help/opinion will be greatly appreciated!

    Would you use one SQL statement to retrieve all of the data for display Yes.
    and use logic to avoid printing the redundant part of the dataNo.
    I believe in minimising the number of queries. If it is a simple one-many join on a db table, then one query is better than one + n queries.
    However I prefer to store the objects in a bean class with attributes other than strings - ie one object, with a collection attribute to hold the related "many" records.
    Does the fact you are not using Struts mean that you have to use scriptlet code? (shudder)
    Or are you using JSTL, or other custom tags?
    How about tools like Ant? Junit testing?
    The way that I am doing everything just seems so cumbersome and difficult
    compared to using Struts and JDO before.Anything different takes adjusting to. Sounds like you know what you're doing for the most part. I agree, in terms of best practices what you have described so far sounds like a step backwards from what you were previously doing.
    However I wouldn't go complaining about it too loudly, too quickly. If you're new on the block theres nothing like making a pain of yourself, and complaining how backwards the work they have done is to put your new workmates' backs up
    Look on it as a challenge. Maybe discuss it quietly with a team leader, to see if they understand how much easier/better/less error prone such approaches can be?
    Struts, cumbersome as it can be, definitely has the advantage of pushing you to follow good MVC practice.
    Good luck,
    evnafets

  • RecordSet in JSP page with MySQL database

    I want to create a recordset for my jsp page but i don't know how to do it at all. I know that I need a connection , a statement and a RecordSet. But after that I am Lost.
    I want "First" "Previous" "Next" "Last" to be shown as hyperlinks into my webpage

    Sorry when I say Recondset I mean <b >RecordSet Navigator</b>

  • JSP / HTML doubt ...

    Hi every one!
    My doubt may seem to be a waste doubt, but its a doubt,so..,
    Can we use JSP tags(like <%,<%=) in a servlet program.
    And can we use a JSP tag in between or inside a html tag as.,
    <a href=my.html name=<%=val%> >Hi</a> ,,where val is a string object holding some string say Hi.Can we use like this?
    Plz guide me! Thnkz in advance...

    Yes, like Yogesh mentioned it is possible to include a JSP expression
    <%=someVariable%> inside the value attribute of an HTML tag.
    However, there is a new and improved way of doing this. In case you are using the latest versions of everything - JSP 2.0 , Servlet 2.4 etc
    instead of using a JSP expression like this <%=someVariable%> , now you can do it in a much simpler syntax with EL like this ${someVariable}If you install JSTL 1.1 and configure it , there are much simpler and better ways to do things with JSPs now.
    For example this JSP scriptlet :
    <%
    for (int i=0; i < 10; i++){
        out.println(i);
    %>could be written in JSTL inside a JSP as
    <c:forEach begin="1" end="10" var="index" step="1">
        ${index} <br/>
    </c:forEach>The above is just a small example and doesn't show all the benefits of JSTL, but when the application grows large if one uses just JSP scriptlets and expressions the code becomes unmanageable.
    With JSTL the code looks much cleaner , simpler as it encapsulates all business logic to the business layer.
    If you are new to JSPs then you can get familiar with scriptlets and expressions, but I encourage you to make use of the benefits of JSTL after you become familiar with the basics of JSPs.
    Message was edited by:
    appy77

  • Get value from Table/Recordset Cell into a JSP variable

    Can anyone please help with this ?...
    I need to get a cell value from a selected row of a table into a variable to pass to a java bean.
    1 - The dynamic table is populated by a recordset named "rs" and has a submit button for each row .
    2 - The user clicks on the corresponding button to select the row.
    3 - The recordset retrieved the ID for that row in the query, but does not display it in the table.
    I have tried :
    <% String ID = rs.getString("bookid");%>
    <% Library.bookConfirm(ID);%>
    But this fails saying that it "cannot resolve variable rs..."
    Yet the recordset populates correctly and its name is "rs"
    Is there another way to do this perhaps ?... ie: put the id in a column of the table and get the cell value ?...
    What would be the syntax to get the ID cell value of that selected row on the button click ?...
    Your feed back would be greatly appreciated.
    Thank you.

    Create a new rs
    ResultSet rs1 = statement.executeQuery(query);
    and use getstring to access the individual cell.

Maybe you are looking for

  • Incoterms

    Hi all Can some one plese explain me what is 'Terms of Payment' & 'Incoterms' in vendor master record. some scenarios where we need to create new ones other than standard Regards Bhushan

  • Mac pro running slow, rainbow all the time, can't repair disk

    So about a week ago my mac pro was running fine as i worked for a few hrs. then all the sudden i was clicking through firefox and i got a rainbow, it lasted ten minutes and i couldn't close the program, when i tried to click anything else it froze as

  • Using a script on an indesign server

    I am new to working on an InDesign Server. I have built a template that requires a javascript for alignment issues. What needs to be done so the script is accessed when the file is accessed via the server?

  • Capacity consumption issue

    Hello friends, I have the following scenario: II am using PP-PI model, Recipe for a Material A has fixed duration of 10 hrs for Capacity consumption.  When there is 1 process order created for 3 pc of A, system consumes 10 hrs of capacity. This works

  • Very old games! where can I find them?

    Ok, I had an old Quadra 605 from back in '93. It came with some awesome Text/graphic games. Problem is that when I backed them up back then, I used a SyQuest Drive (ARG!). The things were crap. But I lost all my games. The ones I'm looking for are th