jdbc to odbc | Familiar Sight | | Join Date: Nov 2007
Posts: 153
| |
Hi all,
After an hour of searching i have decided to surrender and ask! - s.execute("INSERT INTO customers values(?," +name + "','" + address + "','" + email + "','" + phone + "','" + purchase + "')")
is saying [Microsoft][ODBC Microsoft Access Driver]COUNT field incorrect
This is because of the first value ?. I have an auto increment table in microsoft access but if I don't enter ? as the value for the auto increment column i get a mismatch error.
Any one know the proper syntax for my problem(how to let access add the auto increment data when working via java)?
Regards
Brendan
|  | Expert | | Join Date: Mar 2007
Posts: 10,611
| | | re: jdbc to odbc Quote:
Originally Posted by brendanmcdonagh Hi all,
After an hour of searching i have decided to surrender and ask! - s.execute("INSERT INTO customers values(?," +name + "','" + address + "','" + email + "','" + phone + "','" + purchase + "')")
is saying [Microsoft][ODBC Microsoft Access Driver]COUNT field incorrect
This is because of the first value ?. I have an auto increment table in microsoft access but if I don't enter ? as the value for the auto increment column i get a mismatch error.
Any one know the proper syntax for my problem(how to let access add the auto increment data when working via java)?
Regards
Brendan I don't know if it matters much but you're missing a single tick (') before the name field. (it's better to use PreparedStatements for this purpose for a couple of reasons).
kind regards,
Jos
|  | Lives Here | | Join Date: Jan 2007 Location: India (West-Bengal)
Posts: 2,451
| | | re: jdbc to odbc Quote:
Originally Posted by brendanmcdonagh This is because of the first value ?. I have an auto increment table in microsoft access but if I don't enter ? as the value for the auto increment column i get a mismatch error. -
String query = "insert into TABLE(col1....coln) values(val1....valn)";
-
s.execute(query);
-
| | Familiar Sight | | Join Date: Nov 2007
Posts: 153
| | | re: jdbc to odbc - String query = "INSERT INTO customers values(?,'" +name + "','" + address + "','" + email + "','" + phone + "','" + purchase + "')";
-
s.execute(query);
new code - same error message!
Regards
Brendan
|  | Lives Here | | Join Date: Jan 2007 Location: India (West-Bengal)
Posts: 2,451
| | | re: jdbc to odbc Quote:
Originally Posted by brendanmcdonagh - String query = "INSERT INTO customers values(?,'" +name + "','" + address + "','" + email + "','" + phone + "','" + purchase + "')";
-
s.execute(query);
new code - same error message!
Regards
Brendan Why are you putting ? mark?
Are you trying to put the value automatically?
Did you see my post ... simply mention the column name and put the values accordingly and no need to put the put auto increment value.
| | Lives Here | | Join Date: Sep 2006
Posts: 12,070
| | | re: jdbc to odbc Quote:
Originally Posted by dmjpro Why are you putting ? mark?
.... Because that is the correct way of doing it.
Read the PreparedStatement API for details.
|  | Expert | | Join Date: Mar 2007
Posts: 10,611
| | | re: jdbc to odbc Quote:
Originally Posted by r035198x Because that is the correct way of doing it.
Read the PreparedStatement API for details. That is not what the OP attempted to use it for; the first column of that table is an auto-increment column and the OP was trying to express ? as 'I don't know what to put here'; Dmjpro is probably right here: explicitly mention all column names for which values are supplied.
kind regards,
Jos
| | Familiar Sight | | Join Date: Nov 2007
Posts: 153
| | | re: jdbc to odbc - String query = "INSERT INTO customers(id, customerName, customerAddress, customerEmail, customerNumber, customerPurchase/s) values('" +name + "','" + address + "','" + email + "','" + phone + "','" + purchase + "')";
This is now showing a sql syntax error when executed??
|  | Expert | | Join Date: Mar 2007
Posts: 10,611
| | | re: jdbc to odbc Quote:
Originally Posted by brendanmcdonagh - String query = "INSERT INTO customers(id, customerName, customerAddress, customerEmail, customerNumber, customerPurchase/s) values('" +name + "','" + address + "','" + email + "','" + phone + "','" + purchase + "')";
This is now showing a sql syntax error when executed?? I can see a /s in that string; better print out that string before you feed it to your sql engine. For your next post: it would be convenient if we know too what the exact error message was.
kind regards,
Jos
| | Familiar Sight | | Join Date: Nov 2007
Posts: 153
| | | re: jdbc to odbc
and the answer is...... - s.execute("INSERT INTO customers(customerName, customerAddress, customerEmail, customerNumber, customerPurchase) values('" +name + "','" + address + "','" + email + "','" + phone + "','" + purchase + "')");
p.s any one know how to close a frame rather than just setVisible(false)
I have frame1 opening frame2(I want to close frame1 here) and then frame2 is opening a new instance of frame1(i want to close frame2 here)
Any ideas?
|  | Expert | | Join Date: Mar 2007
Posts: 10,611
| | | re: jdbc to odbc Quote:
Originally Posted by brendanmcdonagh and the answer is...... - s.execute("INSERT INTO customers(customerName, customerAddress, customerEmail, customerNumber, customerPurchase) values('" +name + "','" + address + "','" + email + "','" + phone + "','" + purchase + "')");
p.s any one know how to close a frame rather than just setVisible(false)
I have frame1 opening frame2(I want to close frame1 here) and then frame2 is opening a new instance of frame1(i want to close frame2 here)
Any ideas? So it was that misplaced / character? You can get rid of a JFrame by calling the dispose() method inherited from the Window class.
kind regards,
Jos
|  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,383 network members.
|