wood burning stoves 2.0*
The moose likes JDBC and the fly likes Syntax error in SQL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Syntax error in SQL" Watch "Syntax error in SQL" New topic
Author

Syntax error in SQL

Femi Ojambati
Greenhorn

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: 1321



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

means,

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


Saifuddin..
[Blog][Linkedin] How To Ask Questions On JavaRanch My OpenSource
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Syntax error in SQL
 
Similar Threads
Exception in Deleting Parent and Child entity
insert boolean value in a column with data type bit
selecting rows from a table
how to retrive the data of the last row in the table ?
Syntax error in INSERT statement