• 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

Insert into PrepareStatement Using Field Name

 
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello
Is it possible to Insert the value in DB, using the field name. I couldnt able to find such Method in PreparedStatement..
Something like

String Query = "Insert into table(GROUP_NAME,SOURCE) values (?,?)";

PreparedStatement ps =conn.prepareStatement(Query,Statement.RETURN_GENERATED_KEYS);
// like the below i need
ps.setValue("GROUP",1);
ps.setValue("SOURCE",2)


ps.executeUpdate();
 
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why do you need that? You have already mentioned the field names in the insert statement.
 
vinod balaji
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes ofcourse,
but if i able to specify the field name, i can give the statements in any order..
 
Swastik Dey
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I dont find anything wrong with this

String Query = "Insert into table(SOURCE,GROUP_NAME,) values (?,?)";

PreparedStatement ps =conn.prepareStatement(Query,Statement.RETURN_GENERATED_KEYS);
// like the below i need
ps.setValue(1,sorceValue);
ps.setValue(2,grpValue)


ps.executeUpdate();
 
vinod balaji
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We can insert using the Index.. No problem with that..
Can we insert using the Field name using any PreparedStatement API ?
 
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, you can't. Why would you?
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No , you need to suppy the index numbers ie integer values for correnponding columns.

 
reply
    Bookmark Topic Watch Topic
  • New Topic