|
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
|