If statement in JSP

Hello, I need help with the following . The problem is with the 'If statement'. The query and everything else is working. The value 'reservoir' is something that I want key in manually. Must I declare this value ? if yes, how?
Thank you for your time.
results=stmt.executeQuery("SELECT ASSET.ASSET_ID,ASSET.RESERVOIR_TOTAL_HEAD,ASSET.RESERVOIR_HEAD_PATTERN FROM
ASSET,ASSET_TYPE WHERE ASSET.ASSET_TYPE_ID=ASSET_TYPE.ASSET_TYPE_ID AND ASSET_TYPE.ASSET_TYPE_ID="+ASSET_TYPE_ID[ j ]+"");
     while(results.next())
          bout.write(results.getString("ASSET.ASSET_ID"));
             if (result.getString("ASSET.ASSET_ID").equals("reservoir")) {   /* problem only here*/
               bout.write("\t");
               bout.write(results.getString("ASSET.RESERVOIR_TOTAL_HEAD"));
               bout.write("\t");
               bout.write(results.getString("ASSET.RESERVOIR_HEAD_PATTERN"));
               bout.newLine();
                 bout.newLine();

Hello,
There is nothing wrong with the syntax. And as I suppose the reservoir is a String, so if u want the ASSET.ASSET_ID=="reservoir" then dosome action. If this is the case then the syntac is correct.
The problme might be with the spaces which are coming with the ASSET.ASSET_ID field ( I SUPPOSE NOT SURE). Try to trim the spaces, and then check.
Bye Vasu

Similar Messages

  • Using return statement in jsp

    Hi all,
    I am using return statement in JSP page after a redirect to stop executing that page. If the data bean is not present then it must go to previous page. When this return statement is executed the previous page is displayed but url in browser remains same. Why it is so ?. Is there any other way to tell a JSP page to stop executing and redirect to another page.
    rgds
    Antony Paul

    Hi Antony,
    do you use the "forward()" method or the "redirect()" method???
    rgds
    Howy

  • INSERT statement with JSP

              Does anyone know how to create an INSERT statement with JSP using
              variables??
              I can do the insert if I code the values of the variables in the statement,
              but when I try to use variables to do the insert it tries to insert the
              variable name and not the value of the variable into the table.
              Thanks,
              Doug
              

    "Doug Schaible" <[email protected]> wrote in message news:<bicO7.1279268$[email protected]>...
              > I can do the insert if I code the values of the variables in the statement,
              > but when I try to use variables to do the insert it tries to insert the
              > variable name and not the value of the variable into the table.
              Doug,
              I think you missed the <%= blahblah %> syntax.
              Regards
              drit
              

  • Inserting your own sql-statements in JSP

    How do I use my own sql-statements in JSP combined with the ones
    generated by JDeveloper?
    It seems to me that the following sentences are the ones
    generating the sql for inserting in a database:
    <jbo:DataSource id="ds" appid="MimPKG.MimPKGModule"
    viewobject="BidragView"/>
    <jbo:Row id="newRow" datasource="ds" action="Create">
    <jbo:SetAttribute dataitem="*"/>
    </jbo:Row>
    I would like to have more control and therefore I need to make
    my own sql-statements.
    Is that possible?
    Thanks
    Leise

    You can use ExecuteSQL data tag to do so. It allows you to
    include your own query like insert, update etc.

  • Import statement in JSP

              Hi
              I am maintaining a system done by one of our vendors.
              Application is deployed in WLS 7.0.
              When I imported the Jsp's into my IDE , I got errors where java.util classes are
              used in the JSP's and the import statement is missing.
              Most of the Jsp's are like this,
              It is working fine in the production server.
              In the IDE i am forced to put the import statement and that is what I expect.
              But how can it work in the production server without any issue.
              Can someone advise me on this
              Thanks
              DN
              

    <%@page import="java.util.calendar" %>
    Oops... forgot the "page" in there ...That's what I get for using GUI's too much!!! :)

  • Error msg in IF ELSE statement in jsp page, Need help

    Below is my code I am trying to execute, but keep getting an error:
    Compilation error occured:
    Found 1 errors in JSP file:
    D:\\http\\proFolder\\student.jsp:130: Syntax: "}" inserted to complete StatementNoShortIf
    <%if (assess.getNumberValue() > 0) {%>
         <%if ((assess.getTotalCost(appForm)) <= (assess.getNumberValue())) {%>
         <strong><%=assess.getTotalCost(appForm)%></strong>      
            <%}%>
    <%}%>
    <%else {%>
         <%=assess.getTotalCost(appForm)%>
    <%}%>Basically, What I am trying to do is follow this logic:
    IF method getNumberValue() is greater then 0, then execute the second IF statement that
    is, If method getTotalCost() is less then or equal to getNumberValue() then display value of method getTotalCost()
    End Second IF
    End First IF
    Now if the First IF fails ( that is getNumberValue() is not gether then 0)
    then execute the else statement
    Could someone please guide me what I am doing wrong, and what would be the correct way of write the IF else code
    Thanks,

    <%     if (assess.getNumberValue() > 0) {
              if ((assess.getTotalCost(appForm)) <= (assess.getNumberValue())) {
    %>
                   <strong><%=assess.getTotalCost(appForm)%></strong>      
    <%          
    %>
    <%
         else {
    %>
              <%=assess.getTotalCost(appForm)%>
    <%
    %>

  • Odd results from SQL statement in JSP

    Hi.
    Getting very strange results from my SQL statement housed in my JSP.
    the last part of it is like so:
    "SELECT DISTINCT AID, ACTIVE, REQUESTOR_NAME, ..." +
    "REQUESTOR_EMAIL" +
    " FROM CHANGE_CONTROL_ADMIN a INNER JOIN CHANGE_CONTROL_USER b " +
    "ON a.CHANGE_CTRL_ID = b.CHANGE_CTRL_ID " +
      " WHERE UPPER(REQUESTOR_NAME) LIKE ? ";   I've set the following variables and statements:
    String reqName = request.getParameter("requestor_name");
    PreparedStatement prepstmt = connection.prepareStatement(preparedQuery);
    prepstmt.setString(1, "%" + reqName.trim().toUpperCase() + "%");
    ResultSet rslts = prepstmt.executeQuery();
    rslts.next();
    int aidn = rslts.getInt(1);          
    int actbox = rslts.getInt(2);     String reqname = rslts.getString(3).toUpperCase();
    String reqemails = rslts.getString(4);
    String bizct = rslts.getString(5);
    String dept = rslts.getString(6);
    String loc = rslts.getString(7);
    Date datereq = rslts.getDate(8);
    String busvp = rslts.getString(9);
    AND SO ONSo then I loop it, or try to with the following:
    <%
      try {
      while ((rslts).next()) { %>
      <tr class="style17">
        <td><%=reqname%></td><td><%=reqemails %></td><td><%=bizct %></td>td><%=dept %></td>
       <td><%=aidn %></td>
      </tr>
      <%
    rslts.close();
    selstmt.close();
    catch(Exception ex){
         ex.printStackTrace();
         log("Exception", ex);
    %>AND so on, setting 13 getXXX methods of the 16 cols in the SQL statement.
    Trouble is I'm getting wildly inconsistent results.
    For example, typing 'H' (w/o quotes) will spit out 20 duplicate records of a guy named Herman, with the rest of his corresponding info correct, just repeated for some reason.
    Typing in 'He' will bring back the record twice (2 rows of the complete result set being queried).
    However, typing in 'Her' returns nothing. I could type in 'ell' (last 3 letters of his name, Winchell) and it will again return two duplicate records, but typing in 'hell' would return nothing.
    Am I omitting something crucial from the while statement that's needed to accurately print out the results set without duplicating it and that will ensure returning it?
    There's also records in the DB that I know are there but aren't being returned. Different names (i.e. Jennifer, Jesse, Jeremy) won't be returned by typing in partial name strings like Je.
    Any insight would be largely appreciated.
    One sidenote: I can go to SQL Plus and accurately return a results set through the above query. Having said that, is it possible the JDBC driver has some kind of issue?
    Message was edited by:
    bpropes20
    Message was edited by:
    bpropes20

    Am I omitting something crucial from the while
    statement that's needed to accurately print out the
    results set without duplicating it and that will
    ensure returning it?Yes.
    In this code, nothing ever changes the value of reqname or any of the other variables.
      while ((rslts).next()) { %>
      <tr class="style17">
        <td><%=reqname%></td><td><%=reqemails %></td><td><%=bizct %></td>td><%=dept %></td>
       <td><%=aidn %></td>
      </tr>
      <%
    } You code needs to be like this:while (rslts.next()) {
      reqname = rslts.getString(3).toUpperCase();
      reqemails = rslts.getString(4);
      bizct = rslts.getString(5);
      dept = rslts.getString(6);
      loc = rslts.getString(7);
      datereq = rslts.getDate(8);
      busvp = rslts.getString(9);
    %>
      <tr class="style17">
        <td><%=reqname%></td><td><%=reqemails %></td><td><%=bizct %></td>td><%=dept %></td>
       <td><%=aidn %></td>
      </tr>
      <%
    There's also records in the DB that I know are there
    but aren't being returned. Different names (i.e.
    Jennifer, Jesse, Jeremy) won't be returned by typing
    in partial name strings like Je.Well, you're half-right, your loop won't display all the rows in the result set, because you call rslts.next(); once immediately after executing the query. That advance the result set to the first row; when the loop is entered, it starts displaying at the 2nd row (or later if there are more next() calls in the code you omitted).

  • Problem on delete statement in JSP

    org.apache.jasper.JasperException: An exception occurred processing JSP page /proj/AdminLog.jsp at line 130
    127: Driver Driverrs3 = (Driver)Class.forName(MM_Conn_DRIVER).newInstance();
    128: Connection Connrs3 = DriverManager.getConnection(MM_Conn_STRING,MM_Conn_USERNAME,MM_Conn_PASSWORD);
    129: PreparedStatement Statementrs3 = Connrs3.prepareStatement("DELETE *  FROM database.credentials  WHERE UserId = 16");
    130: ResultSet rs3 = Statementrs3.executeQuery();
    root cause
    javax.servlet.ServletException: java.sql.SQLException: Can not issue data manipulation statements with executeQuery().i also tried executeUpdate(); but it is still not working.

    is it possible to reference a javascript variableinside a JSP block?
    what i am trying to do is to delete all rows that are checked from the list on button clickNo it is not possible.
    The button has to submit the form, and then you use request.getParameter() to find out which checkboxes were checked.
    The best approach is to give all your checkboxes the same name, and the value being the id you want to delete.
    eg
    <input type="checkbox" name="deluser" value="42">
    <input type="checkbox" name="deluser" value="69">
    <input type="checkbox" name="deluser" value="666">
    then in your java/servlet code
    // using a prepared statement in this case is more efficient. 
    // Can reuse the same statement multiple times.
    PreparedStatement stmt = connect.prepareStatement("delete from credentials where UserId = ?";
    // retrieve the selected checkboxes.
    String[] selectedIds = request.getParameterValues("delUser");
    // check to see if any were checked
    if (selectedIds != null){
      // iterate over all userids marked for deletion
      for (int i=0; i<selectedIds.length; i++){
        int idToDelete = Integer.parseInt(selectedIds);
    stmt.setInt(1, idToDelete);
    stmt.execute();
    Cheers,
    evnafets

  • Regarding comment statement in JSP Page

    Hai to All,
    I have written one small jsp page which checks the given name and display the entered name. This is the code which i have written. Its working fine.
    <html>
    <%
    String name = request.getParameter("txtName");
    out.println("THe Name is"+name);
    out.println("<br><br><br>");
    if(name.equals("Balaji"))
    %>
    <input type=Label value="Welcome Balaji">
    <%
    else
         if(name.equals("Kumaran"))
         %>
         <input type=Label value="Welcome Kumaran">
         <%
              else if(name.equals("Kandhan"))
              %>
              <input type=label value="Welcome Kandhan">
              <%
         else{
              %>
              <input type=label value="Welcome!!! Welcome !!!!">
              <%
              %>
    <h3> Code Ends Here</h3>
    </html>
    But if want to comment an else if block like this it shows some error like else without if.... delete else token. can someone please help me.
    <html>
    <%
    String name = request.getParameter("txtName");
    out.println("THe Name is"+name);
    out.println("<br><br><br>");
    if(name.equals("Balaji"))
    %>
    <input type=Label value="Welcome Balaji">
    <%
    else
         if(name.equals("Kumaran"))
         %>
         <input type=Label value="Welcome Kumaran">
         <%
         /*     else if(name.equals("Kandhan"))
              %>
              <!--
              <input type=label value="Welcome Kandhan">
              -->
              <%
         else{
         %>
         <input type=label value="Welcome!!! Welcome !!!!">
         <%
         %>
    <h3> Code Ends Here</h3>
    </html>

    <!--
    <input type=label value="Welcome Kandhan">
    -->That is an HTML comment, not a Java comment. So it gets sent to the client with Java code that looks like this (sorta):
    out.println("<!--");
    out.println("<input ...>");
    out.println("-->");So that means, between the end of the previous if statement there is some java code (the out.printlns) before you get to the else, which isn't allowed.

  • SQL LIKE statement in JSP

    I tried to write a query in jsp page using LIKE statement. However, Apache Tomcat report back an error in the query string. I tried to run the same query style in MS Access and it works. Can someone please tell me where is the error in jsp code:
    JSP Code:
    sql = "SELECT tblStudent.firstName, tblStudent.lastName, tblStudent.studentID FROM tblStudent WHERE (((tblStudent.firstName) LIKE '%" + g_firstNameInput + "%')) ORDER BY tblStudent.firstName";
    MS Acccess:
    SELECT tblStudent.firstName, tblStudent.lastName, *
    FROM tblStudent
    WHERE (((tblStudent.firstName) Like '*e*'))
    ORDER BY tblStudent.firstName;
    PS: I tried changing from '%' to '*' already, but still does not work
    Thanks

    Don't use JSP for SQL querries... to complicated.
    1) Write a Java application that does what you want (as far as interacting with the database
    2) Isolate the database access code into its own class/classes
    3) Double check that you can then use those isolated classes inside a command line application
    4) Adapt the code you used in 3) to use those same classes from a JSP - preferrably using Java Beans and DTOs

  • INSERT statement in JSP using variables

    People,
    I am having problems inserting data from JSP into a MySQL database.
    For example the following works perfectly fine:
    String query = "INSERT INTO `test2` (`name`, `topic`, `message`) VALUES ('Jane Doe', 'Hi there', 'Example message')";
    But, however the problems take place if I try to use variable values as parameters instead of pre-defined strings.
    E.g. the following (among a 100 other ways I have tried by now) does not work):
    String query = "INSERT INTO `test2` (`name`) VALUES (`" + userName +"`)";
    stmt.executeUpdate(query);
    This did not work either:
    PreparedStatement PStmt = myConn.prepareStatement("insert into (`name`) values (?)");
    PStmt.setString(1, new String("`" + userName + "`"));
    PStmt.executeUpdate();
    I have tried without parenthesis etc. but what I pretty much get every time is:
    500 Servlet Exception
    java.sql.SQLException: Column not found: Unknown column 'Jane' in 'field
    list'
         at org.gjt.mm.mysql.MysqlIO.sendCommand(MysqlIO.java:508)
         at org.gjt.mm.mysql.MysqlIO.sqlQueryDirect(MysqlIO.java:561)
         at org.gjt.mm.mysql.MysqlIO.sqlQuery(MysqlIO.java:646)
         at org.gjt.mm.mysql.Connection.execSQL(Connection.java:973)
         at org.gjt.mm.mysql.Connection.execSQL(Connection.java:897)
         at org.gjt.mm.mysql.Statement.executeUpdate(Statement.java:230)
         at org.gjt.mm.mysql.jdbc2.Statement.executeUpdate(Statement.java:99)
         at sql3_jsp._jspService(/sql3.jsp:49)
         at com.caucho.jsp.JavaPage.service(JavaPage.java:87)
         at com.caucho.jsp.JavaPage.subservice(JavaPage.java:81)
         at com.caucho.jsp.Page.service(Page.java:474)
         at com.caucho.server.http.FilterChainPage.doFilter(FilterChainPage.java:166)
         at com.caucho.server.http.Invocation.service(Invocation.java:277)
         at com.caucho.server.http.CacheInvocation.service(CacheInvocation.java:129)
         at com.caucho.server.http.RunnerRequest.handleRequest(RunnerRequest.java:334)
         at com.caucho.server.http.RunnerRequest.handleConnection(RunnerRequest.java:266)
         at com.caucho.server.TcpConnection.run(TcpConnection.java:140)
         at java.lang.Thread.run(Thread.java:484)
    I do not know much about SQL or JDBC but the material I have seen makes me believe
    that I am pretty much doing the right thing.
    What is the right way of doing this?
    I would greatly appreciate any feedback.

    Hi,
    I think i know the problem.
    Take a look on your String code :
    "INSERT INTO `test2` (`name`, `topic`, `message`) VALUES ('Jane Doe', 'Hi there', 'Example message')";
    it is not necessary to put QUOTE for the tablename and the fields.
    my code work with :
    String query = "INSERT INTO test2 VALUES( ' " + 123 + " ' ) ";
    ( if you inserting into all fields in your table ) OR
    String query = "INSERT INTO test2 ( abc ) VALUES( ' " + 123+ " ' ) ";
    ( if you need to select certain fields ).
    or you can try to refer to :
    http://www.w3schools.com/sql/sql_insert.asp
    hope this help.

  • Print statement in JSP page after redirection

    Hi,
    I have written a JSP page and in that i am redirecting it to another page. Now after redirection i am printing a statement on the console. It is getting printed whereas when i am printing the same on the browser i am not able to print that. Please can any one tell me the difference between printing the same on the console and browser.
    My first JSP page(one.jsp)
    <%
         response.sendRedirect("two.jsp");
         out.println("After redirect");
         System.out.println("After out");
    %>
    My second JSP(two.jsp)
    <%
         out.println("In two.jsp");
    %>
    Thanks in advance
    regards
    Prashanth

    The sendRedirect sets a code in the HTTP response being sent to the client (I believe it is a 302 code but I am not sure off hand) and then proceeds to process the rest of the JSP on the server which is why the print statement shows up in the console.
    The out.println writes to the HTTP response output stream. The client gets the response and sees the HTTP Header code telling it to make a new request so it stops processing the response message and sends a new request message which is why the out.println message is not seen in the browser.

  • Problem with printing debug statements in JSP page

    Hi all,
    I am debugging an application with System.out.println() statements - my debug statements in the *.java class printed just fine, but when I do the same thing in my JSP page, nothing gets printed out.
    I am already wrapping my System.out.println() statements inside the <% %> tag.
    Does anyone know what may be causing this? Any help will be greatly appreciated!
    - JL

    Where do you expect to see the output?
    System.out.println will write to the console/logs
    They WON'T write to the JSP page.
    If you check your error/output logs you will probably find the statements there.
    If you want to print things into the JSP page, just use out.println.
    "out" is an implicit reference to the current JSPWriter.
    Cheers,
    evnafets

  • How to write statement using LIKE statement in jsp

    hi
    I am new to jsp. I would like to retrive the data from database using like command. But my query dosen't work well. Can you help me in this topic.
    String name = request.getParameter("username");
    int i = st.executeQuery("select * from emp where empname LIKE '%name%'");
    Plase help me..
    Thanking you
    sure...

    Using LIKE :
    ==========
    The following SQL statement will return persons with first names that start with an 'O':
    SELECT * FROM Persons
    WHERE FirstName LIKE 'O%'
    The following SQL statement will return persons with first names that contain the pattern 'la':
    SELECT * FROM Persons
    WHERE FirstName LIKE '%la%'
    Hope this might have helped you
    REGARDS,
    RaHuL

  • Insert statements in jsp

    I am having a problem. I would like to insert some form data into a database using jsp but I have coded it and it gives me an error insert statement syntax is incorrect here is my code
    <%@page import="java.sql.*"%>
    <html>
    <head>
    <title>
    </title>
    </head>
    <body>
    <%
    String _driver = "sun.jdbc.odbc.JdbcOdbcDriver";
    String _url = "jdbc:odbc:testdata";
    try {
                 Class.forName (_driver);
                 String dataSourceName = _url;
                 String dbURL = dataSourceName;
                 Connection con = DriverManager.getConnection(dbURL);
                 Statement s = con.createStatement();
                 String insert;
                 insert = "insert into order (field1 , field2 , field3) values ('"
                 + request.getParameter("item1") + "' , '" + request.getParameter("item2") + "' , "
                 + "'" + request.getParameter("item3") + "')";
                 out.print(insert);
                 s.execute(insert);
                 s.close();
                 con.close();
                 }  // closes try statement
                 catch (Exception err) {
                 out.print("ERROR: " + err);
                 }; // closes catch statement
    %>
    <a href="shoppingcart.jsp">go back to shopping cart</a>
    </body>
    </html>here is the error it gives me
    ERROR: java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Syntax error in INSERT INTO statement.
    the insert statement looks right to me but there is something wrong anyone got any ideas. Thanxs in advance.

    AAAHHHH. Order is a reserved word and that was what my table was named. I suppose because of the order by clause it is. Figures spend hours staring at it and it is right there. I have to start using prefixes and suffixes on my code it would save me so much hassel.

  • Remembering the radio button state between jsp pages

    How do i maintain the state of radio buttons when i move from one jsp page to another. Thank you for your help.

    Hi
    If the next JSP is a child window,you can take a JSP hidden variable and you can store radio button state in it and can get the same on child window thorugh window.opener.
    And if its not a child window(JSP),then you can maintain the state in session and get it anywhere.

Maybe you are looking for

  • How do I sync playlists to iphone 4s from itunes with the new update

    how do I add my top 25 playlist to my iphone I updated my itunes and now my playlists are not on my iphone. the only playlist that show now are the ones I made and i tried to select and sync the lists but their still not showing on my iphone.

  • Help!!! Ipod touch problems. PLEASE Help!!!!

    Hey guys, I've been having some trouble with my Ipod i just got. I have a friend who just pick up an Iphone and didn't need his anymore. So I picked it up from him. It was working fine at his house and last night. I was trying to sync my music to it

  • Safari crashes when I open it

    Hello, I recently installed Bluestacks on my mac. It used an install utility called Install Mac, which decided to change the default web page and home page on all my browsers, Ever since I did that, Safari will not open, as soon as I click it in the

  • How can i fix my itunes because i can't see my ipod on it but i can see him in windows documents ?

    i can't put music on my ipod touch help meee itunes can't find my ipod touch so what do i need to do i already reinstalled itunes but same probleme

  • SAP Implementation Certificate

    Hi, One of the SAP training institute in Bangalore makes us write the SAP- Implementation certification exam with the cost of INR 5000 after there training. Is there any use of Implementation certificate and please guide can we go for the Implementat