• 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
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

insert to database...

 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 26909
82
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks... it worked.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic