aspose file tools*
The moose likes JDBC and the fly likes Inserting into a table Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Inserting into a table" Watch "Inserting into a table" New topic
Author

Inserting into a table

Shaan patil
Ranch Hand

Joined: Dec 22, 2007
Posts: 58
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


"You cannot change the truth but truth can change you "
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336


pst.execute();

try executeUpdate() instead. This may not do it, but without knowing what your SQLException says I can't suggest much more.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Shaan patil
Ranch Hand

Joined: Dec 22, 2007
Posts: 58
Hi,

The error says that insufficient value are provided.


Regards
kkk guptha
Greenhorn

Joined: Nov 17, 2007
Posts: 3
Hi,

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

--- KKKGuptha
Shilpa Tendulkar
Ranch Hand

Joined: Jul 29, 2001
Posts: 75
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(?,?,?)


SCJP5
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Inserting into a table
 
Similar Threads
how do i insert more than one row to my table
about hidden from fields
prepared statement is not working according to if condition
how can we use where clause with insert query using preparedStatement?
SQL Exception:General Error