aspose file tools
The moose likes JDBC and the fly likes prepared statement and DB field char Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Databases » JDBC
Reply Bookmark "prepared statement and DB field char" Watch "prepared statement and DB field char" New topic
Author

prepared statement and DB field char

Rajni Patel
Ranch Hand

Joined: Sep 03, 2009
Posts: 84
Hi,

I have a field in Database which is of CHAR(11) type. I am using
prepared statement to set parameter value in this field in Java in DAO class. I used
setString method of prepared statement for this purpose but i didnt get
any success in it.

Can any one help me which prepared statement method should I use to set
parameter in this field.

thanks
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 26192
    
  66

setString() is correct. What error did you get?


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Rajni Patel
Ranch Hand

Joined: Sep 03, 2009
Posts: 84
Thanks for reply.

My query is like this:

sql = "select empname from employ where empno = ?";


Here empno is char(11) in DB.

and then I set value

ps.setString(1,"101");

Originally, there is record which has empno=101 in DB. but in my case there is no data fetch from DB and also not any error is coming.

Thanks
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 16483
    
    2

That just means your query selected zero records, then.

Perhaps you think there is a row in the table containing "101" in the empno column? Is it not possible that row actually contains "101 " or " 101"?
Rajni Patel
Ranch Hand

Joined: Sep 03, 2009
Posts: 84
Thanks for reply.

there is DB field char(11) so in db there is 11 size for that field.

so I have write querey like this.

select empname from emp where trim(empno)= '101';

now its working.

thanks again.
chris webster
Bartender

Joined: Mar 01, 2009
Posts: 1103
    
    7

Use VARCHAR or VARCHAR2 instead of CHAR as your column data-type, to avoid the trailing blanks on your data.


ex-Oracle bloke
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: prepared statement and DB field char
 
Similar Threads
PreparedStatement issue
Merge command workd well , but gives ora-00905 in Java
EJb 2.1 Question
java.sql.SQLException: ORA-01008: not all variables bound
Inserting | into oracle DB