0

I have an access database and trying to use it in java. I want to select it and wrote a statement as

String sql="SELECT * from numeric;";
    try
    {
        rs=s.executeQuery(sql);
        while(rs.next())
        {
            System.out.println(rs.getString(1));
        }
    }

The executeQuery is throwing an exception as

java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Syntax error in FROM clause.

I think the select statement I wrote is correct. Even if i write as

SELECT Webservice FROM numeric;

also gives me an error where Webservice is my column name.

4
  • 1
    Isn't numeric some kind of SQL data type? Try to put the name into paranthesis, i.e. use [numeric]. Are you sure you have named your table numeric? Commented Mar 20, 2014 at 9:00
  • @D.R. Yes, I have kept the table name as numeric. But i will change the table name and try. thank you. Commented Mar 20, 2014 at 9:18
  • @D.R. It is exactly the thing that you have mentioned. The fault is with the table name only. Once I have changed it, the execution is done without error. Thank you. I can upvote the comment as I cannot mark it as an answer. please leave as an answer for others. Commented Mar 20, 2014 at 9:24
  • I've converted my comment into an answer. Commented Mar 20, 2014 at 9:25

3 Answers 3

3

You have to remove the trailing ; at the end of your statement!

Usually you are seperating statements with a ;, but since executing multiple statements in a single statement string is not allowed in JDBC by specification, you can't use semicolons.

Sign up to request clarification or add additional context in comments.

1 Comment

Actually we can use ; because I am using ODBC drivers. It doesn't give me any error with semicolon. I changed the table name and it is working fine now. Thank you for answer.
2

Your table is called numeric which is also an SQL data type. The SQL parser thinks its a data type and your query fails. If you have reserved keywords like this as table names you need to put the table name in parenthesis:

SELECT * FROM [numeric]

Comments

0

In Access database the index starts from one, not zero. Identify the index of webservice first, it mary be two, try out the following statement

System.out.println(rs.getString(2));

3 Comments

If you look at the exception Syntax error in FROM clause. the issue is probably not the call of getString, is it?
yes, even if correct from clause may some times unable to get the value.
It is not an error. And the first one column is Webservice. The table name is only an error.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.