Connecting Tech Pros Worldwide Forums | Help | Site Map

jdbc to odbc

Familiar Sight
 
Join Date: Nov 2007
Posts: 153
#1: Jun 17 '09
Hi all,

After an hour of searching i have decided to surrender and ask!

Expand|Select|Wrap|Line Numbers
  1. 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
JosAH's Avatar
Expert
 
Join Date: Mar 2007
Posts: 10,611
#2: Jun 17 '09

re: jdbc to odbc


Quote:

Originally Posted by brendanmcdonagh View Post

Hi all,

After an hour of searching i have decided to surrender and ask!

Expand|Select|Wrap|Line Numbers
  1. 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
dmjpro's Avatar
Lives Here
 
Join Date: Jan 2007
Location: India (West-Bengal)
Posts: 2,451
#3: Jun 17 '09

re: jdbc to odbc


Quote:

Originally Posted by brendanmcdonagh View Post

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.

Expand|Select|Wrap|Line Numbers
  1. String query = "insert into TABLE(col1....coln) values(val1....valn)";
  2. s.execute(query);
  3.  
Familiar Sight
 
Join Date: Nov 2007
Posts: 153
#4: Jun 17 '09

re: jdbc to odbc


Expand|Select|Wrap|Line Numbers
  1. String query = "INSERT INTO customers values(?,'" +name + "','" + address + "','" + email + "','" + phone + "','" + purchase + "')"; 
  2. s.execute(query);
new code - same error message!

Regards

Brendan
dmjpro's Avatar
Lives Here
 
Join Date: Jan 2007
Location: India (West-Bengal)
Posts: 2,451
#5: Jun 17 '09

re: jdbc to odbc


Quote:

Originally Posted by brendanmcdonagh View Post

Expand|Select|Wrap|Line Numbers
  1. String query = "INSERT INTO customers values(?,'" +name + "','" + address + "','" + email + "','" + phone + "','" + purchase + "')"; 
  2. 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
#6: Jun 17 '09

re: jdbc to odbc


Quote:

Originally Posted by dmjpro View Post

Why are you putting ? mark?
....

Because that is the correct way of doing it.
Read the PreparedStatement API for details.
JosAH's Avatar
Expert
 
Join Date: Mar 2007
Posts: 10,611
#7: Jun 17 '09

re: jdbc to odbc


Quote:

Originally Posted by r035198x View Post

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
#8: Jun 17 '09

re: jdbc to odbc


Expand|Select|Wrap|Line Numbers
  1. 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??
JosAH's Avatar
Expert
 
Join Date: Mar 2007
Posts: 10,611
#9: Jun 17 '09

re: jdbc to odbc


Quote:

Originally Posted by brendanmcdonagh View Post

Expand|Select|Wrap|Line Numbers
  1. 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
#10: Jun 17 '09

re: jdbc to odbc


and the answer is......

Expand|Select|Wrap|Line Numbers
  1. 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?
JosAH's Avatar
Expert
 
Join Date: Mar 2007
Posts: 10,611
#11: Jun 18 '09

re: jdbc to odbc


Quote:

Originally Posted by brendanmcdonagh View Post

and the answer is......

Expand|Select|Wrap|Line Numbers
  1. 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
Reply