Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Prepared Statement  RSS feed

 
Ransika deSilva
Ranch Hand
Posts: 524
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello;
I am writting a stock control system. in there to enter new stock i am using below code. the problem is that it works fine when i enter all "numeric values". but if i enter a letter for example 'a'. it gives a sql exception saying "too few parameters. expected 1". could you please give me a solution for this. i am using microsoft access data base.

PreparedStatement st_stockaddps=st_stockaddcon.prepareStatement("INSERT INTO inventory VALUES("+st_itemcodest+","+st_descriptionst+","+st_ppust+","+st_qtyst+","+st_reorderlevelst+","+st_suppliercodest+","+st_totalcostst+","+st_totalcostst+")");
st_stockaddps.executeUpdate();
thanks
 
Nilesh Pereira
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First of all, this is not a Swing/JFC/AWT question.
Please refer http://java.sun.com/docs/books/tutorial/jdbc/basics/prepared.html to see how to use Prepared Statements.
 
indian greenhorn
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ur question regarding the prepared statement.
It may be that it is due to mismatch of datatype. Or may be that u are trying to insert with less number of values against the original number of values existing in the concerned table.
Hope u got the thing right. If else contact at pkrishna_74@hotmail.com
regards,
Krishna
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!