Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-25-2008, 07:52 AM
Member
 
Join Date: Mar 2008
Posts: 4
haneeshrawther is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 04-25-2008, 07:59 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 2,532
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Is the sure your DB connection and query is correct?
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
(Close on July 27, 2008)
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 04-25-2008, 10:49 AM
Member
 
Join Date: Mar 2008
Posts: 4
haneeshrawther is on a distinguished road
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?
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Prepared statement pooling (JDBC 3.0) JavaForums Java Blogs 0 04-18-2008 04:20 PM
Using Prepared Statement Java Tip Java Tips 0 02-06-2008 10:22 AM
Help with if statement carl New To Java 1 08-06-2007 08:53 AM
Statement or Prepared Statement ? paty Database 3 08-01-2007 05:45 PM
If Statement aDrizzle New To Java 4 07-08-2007 09:55 PM


All times are GMT +3. The time now is 01:03 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org