Forums Register Login

INSERT Issue

+Pie Number of slices to send: Send
I am trying to insert some data into an Access DB. Here is my sql statement.

st is an object of Statement.
I get this error message [Microsoft][ODBC Microsoft Access Driver]To few parameters. Expected 3
I table only has three fields and I am only passing it three values in the order they are to go in. I tested the sql statement in Access and it worked. Please Help
[ Edited by Dave to format code ]
[ February 24, 2002: Message edited by: David O'Meara ]
+Pie Number of slices to send: Send
use single quotes around your strings instead of double quotes:
String sql = "INSERT INTO PhoneList VALUES('"+state+"','"+number.substring(1,4)+"','"+number.substring(5, number.length())+"')";
a way to verify that the SQL statement is correct is to System.out.println(sql); where 'sql' is the String that you used in your code. Cut and paste the output to your MS Access SQL editor and run it. The error message you get there will be much more informative than the one that JDBC-ODBC supplies.
I have seen that error message used out of context before by JDBC-ODBC. It also means that you have a spelling mistake on your column names or table names in a query.
Jamie
+Pie Number of slices to send: Send
I have tried your code. Change the double quotes to single quotes and it will work. Must be an ODBC thing (which the JDBC-ODBC uses).
just a sidenote:
String number = "1234567890";
number.substring(1,4) equals "234"
number.substring(5,number.length()) equals "67890"
you lose the numbers "1" and "5" from the number string. If that is what is intended then disregard this sidenote.
Jamie
[ February 22, 2002: Message edited by: Jamie Robertson ]
+Pie Number of slices to send: Send
Yes the single quotes worked I tried the Access SQL window and it worked fine with both single and double quotes. The substring usage is because the number object is a telephone number (444)111-2345
Thanks for the help everyone
+Pie Number of slices to send: Send
I have the same problem and couldn't resolve it with your solution.
Could you explain???
Is it "' (double and single)or'"(single and double quote).
I don't see well on my screen.
Thx for your answers!!!
+Pie Number of slices to send: Send
 

Originally posted by Younes Essouabni:
I have the same problem and couldn't resolve it with your solution.
Could you explain???
Is it "' (double and single)or'"(single and double quote).
I don't see well on my screen.
Thx for your answers!!!


It depends on where in the string it occurs. In general, the single quote must be contained in the String. So this is how it should be:

This would translate into "SELECT * FROM emp where name = 'John Doe' and age = 23"
Hope this explains it well enough for you.
Jamie
[ February 28, 2002: Message edited by: Jamie Robertson ]
+Pie Number of slices to send: Send
and will break if I put my name in...
+Pie Number of slices to send: Send
 

Originally posted by David O'Meara:
and will break if I put my name in...


He's not supposed to know about that until he posts in a few more weeks having that error. Come on Dave, this is how you keep them coming back! Besides, if we had to warn people about all the possible errors they may encounter on their first posting, the forum database would run out of room... fast! Especially with the volume of people using MS Access and the jdbc dbc bridge
Jamie
p.s.
I always thought it was deserving that the graemlin that appears when you type in jdbc: odbc is the embarassment graemlin!
If you are using a wood chipper, you are doing it wrong. Even on this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1633 times.
Similar Threads
jdbc:odbc insert error fails with code -3502
problem in inserting data into ms access
Simple mdb connection Error
How to INSERT records into Excel File using JDBC
insert to database...
Thread Boost feature
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 12:55:11.