Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2008
    Posts
    6
    Rep Power
    0

    Question Prblem in Prepared Statement

    I write a program for reading program from database using prepared statement.
    the sql session is

    /* start */

    sql="select max(line_no) as max from expr_rcp where expr_no= ? ";
    pst=conn.prepareStatement(sql);
    pst.setString(1,exprNo);
    rst=pst.executeQuery();
    if(rst.next())
    {
    lineNo=rst.getInt("max");
    System.out.println("lineNo:::"+lineNo);
    }

    /* end */

    i enter exprNo ='855027500001'
    but this snippet nothing returns. After that i try the following code

    /* start */

    sql="select max(line_no) as max from expr_rcp where expr_no= '"+exprNo+"' ";
    pst=conn.prepareStatement(sql);
    rst=pst.executeQuery();
    if(rst.next())
    {
    lineNo=rst.getInt("max");
    System.out.println("lineNo:::"+lineNo);
    }

    /* end */

    i enter the same exprNo. but this time it returns the line no of the entered exprNo

    In my database the value of exprNo is "855027500001 ". it contains some space also.

    I would like to know why it happens like that.
    Please give a reason for that. Why it's happens like this?
    Thanks in advance

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  3. #3
    Join Date
    Mar 2008
    Posts
    6
    Rep Power
    0

    Default

    Yes. I am sure the query and connection is correct. If it is wrong, then how will get the result for the second statement. I just modify the first code as the second code and recompiled. For the second code i get the result. I would like to know what is the different from both the sql query?

Similar Threads

  1. Using Prepared Statement
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-06-2008, 09:22 AM
  2. Help with if statement
    By carl in forum New To Java
    Replies: 1
    Last Post: 08-06-2007, 07:53 AM
  3. Statement or Prepared Statement ?
    By paty in forum JDBC
    Replies: 3
    Last Post: 08-01-2007, 04:45 PM
  4. If Statement
    By aDrizzle in forum New To Java
    Replies: 4
    Last Post: 07-08-2007, 08:55 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •