• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

prepared statement and DB field char

 
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
setString() is correct. What error did you get?
 
Rajni Patel
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Bartender
Posts: 2407
36
Scala Python Oracle Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Use VARCHAR or VARCHAR2 instead of CHAR as your column data-type, to avoid the trailing blanks on your data.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic