• 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

Inserting into a table

 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a table name with table name = account , And The account table has four fields namely, account number,accountname,password,balance.
I am interested in inserting only first three fileds.using the following snippet of the code.


Code snippet to insert into fisrt three fields.

PreparedStatement pst=con.prepareStatement("insert into bank values(?,?,?)");
pst.setInt(1,i);
pst.setString(2,strNme);
pst.setString(3,strPwd);
pst.execute();

But I am getting SQL exception error.What is the workaround solution for the same ?

Regards
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


pst.execute();


try executeUpdate() instead. This may not do it, but without knowing what your SQLException says I can't suggest much more.
 
Shaan patil
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

The error says that insufficient value are provided.


Regards
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

You can get the result with pst.executeUpdate(); instead of pst.execute();

--- KKKGuptha
 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Shaan patil:

PreparedStatement pst=con.prepareStatement("insert into bank values(?,?,?)");
Regards



Try insert query as "insert into bank (accountnumber,accountname,password)
values(?,?,?)
 
roses are red, violets are blue. Some poems rhyme and some are a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic