• 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

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: 28193
95
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic