File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes Syntax error in SQL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Syntax error in SQL" Watch "Syntax error in SQL" New topic

Syntax error in SQL

Femi Ojambati

Joined: Aug 13, 2008
Posts: 6
Please check this code.

Statement stat = conn.createStatement();
String query = "CREATE TABLE Table1(Member ID No INTEGER NOT NULL PRIMARY KEY, Surname VARCHAR(30), Other Names VARCHAR(30), Date of Entry DATE)";
int result = stat.executeUpdate(query);

query = "INSERT INTO Table1 (Member ID No, Surname, Other Names, Date of Entry)
VALUES (001, 'Ojambati', 'Oluwafemi Stephen', '2008-10-15')";
result = stat.executeUpdate(query);

When I tried to run it
An exception was caught, this message was displayed

Error java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Syntax error in field definition

Please where is the error in this code
Muhammad Saifuddin
Ranch Hand

Joined: Dec 06, 2005
Posts: 1323

because SQL doesn't allow the space in Field Name.


[Member ID] is incorrect field name
[Member_ID] is correct.

[Blog][Linkedin] How To Ask Questions On JavaRanch My OpenSource
I agree. Here's the link:
subject: Syntax error in SQL
It's not a secret anymore!