Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9181561
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:20:43+00:00 2026-06-17T18:20:43+00:00

I’m using the following code to execute the query. I want to display the

  • 0

I’m using the following code to execute the query. I want to display the result as “B010025” by using lpad command and concatenation.(25 and B01 is given as input value). But it shows only B0125. When I’m executing this from SQL*Plus it shows the correct result. But in servlet it doesn’t. I can’t understand this. Can anyone help me to get the expected result.

public class PickOfferNo extends HttpServlet {


protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    PrintWriter out = response.getWriter();
    try {
         //TODO output your page here
        out.println("<html>");
        out.println("<head>");
        out.println("<title>Servlet PickOfferNo</title>");  
        out.println("</head>");
        out.println("<body>");
        out.println("<h1>Servlet PickOfferNo at " + request.getContextPath () + "</h1>");
        out.println("</body>");
        out.println("</html>");

    } finally {            
        out.close();
    }
}

// <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    //processRequest(request, response);

    response.setContentType("text/html;charset=UTF-8");
    PrintWriter out = response.getWriter();
    try
    {
        out.println("<html>");
        out.println("<head>");
        out.println("<title>Servlet PickOfferNo</title>");
        out.println("</head>");
        out.println("<body>");
        out.println("<h1>Servlet PickOfferNo at " + request.getContextPath () + "</h1>");
        doPost(request,response);
        out.println("</body>");
        out.println("</html>");
    }
    finally
    {
       out.close(); 
    }
}


@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    //processRequest(request, response);
    String ofrn=null;
    //String cd=null;
    //String no=null;
    String cd="B01";
    String no="25";
    JSONObject obj = new JSONObject();
    //cd=request.getParameter("sec_code");
    PrintWriter out=response.getWriter();
    try
    {
        Class.forName("oracle.jdbc.driver.OracleDriver");
        java.sql.Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@192.168.1.200:1521:pdsm", "test", "test");
             Statement stmt=conn.createStatement();
                 conn.setAutoCommit(true);
                 //ResultSet rs=stmt.executeQuery("select to_char(nvl(max(substr(offerno,4,4)),0)+1) into '"+no+"' from offer1 where div_sec='"+cd+"'");
                 ResultSet rs1=stmt.executeQuery("select lpad(ltrim(rtrim('"+no+"')),4,'0') from dual");
                 //while(rs1.next())
                 ofrn=cd+no;

                 //obj.put("offrn", ofrn);
                 out.println(ofrn);
    }
    catch(Exception e)
    {
        out.println(e.getMessage());
    }
}


@Override
public String getServletInfo() {
    return "Short description";
}// </editor-fold>
}

Thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T18:20:45+00:00Added an answer on June 17, 2026 at 6:20 pm

    It is because you haven’t selected the value return by the database.
    executing

    "select lpad(ltrim(rtrim('"+no+"')),4,'0') from dual"
    

    doesn’t change the value of “no” or “cd”.

    You should get the result set and process it to access the first column in the first row return by the result set.

    Following code should do the assignment. (Not tested.)

    ResultSet rs1=stmt.executeQuery("select lpad(ltrim(rtrim('"+no+"')),4,'0') from dual");
    if(rs1.next()){
    no = rs1.getString(1);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
i want to parse a xhtml file and display in UITableView. what is the
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I am trying to understand how to use SyndicationItem to display feed which is
I am using JSon response to parse title,date content and thumbnail images and place
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.