File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

insert to database...

 
Lesole Mphinyane
Ranch Hand
Posts: 42
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how do add string stored in variable to database?
my code looks like this

i get this error message;
sql error![Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 4.

please help me out with the insert statement
 
Paul Clapham
Sheriff
Pie
Posts: 20196
26
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The driver is simply saying that the table doesn't have columns named sprt, sop, msc, or kid. That's what you told it to insert, data from those columns. It doesn't know anything about those variables in your Java code which happen to have the same names, nor should it.

Here's what you should do instead:

The four question marks in the PreparedStatement act like places where you can plug in values, and the setString(n) method is used to plug values into those places. There are also setInt(n) and setDate(n) methods and several others, which mean you don't need to worry about how to format a date for an SQL query, or what to do about quotes in your string data, or any other annoying formatting issues.
 
Lesole Mphinyane
Ranch Hand
Posts: 42
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks... it worked.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic