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.

Mani
  • 1,364
  • 14
  • 33
  • 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`? – D.R. Mar 20 '14 at 09:00
  • @D.R. Yes, I have kept the table name as numeric. But i will change the table name and try. thank you. – Mani Mar 20 '14 at 09: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. – Mani Mar 20 '14 at 09:24
  • I've converted my comment into an answer. – D.R. Mar 20 '14 at 09:25

3 Answers3

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.

bobbel
  • 3,327
  • 2
  • 26
  • 43
  • 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. – Mani Mar 20 '14 at 09:26
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]

D.R.
  • 20,268
  • 21
  • 102
  • 205
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));
Balayesu Chilakalapudi
  • 1,386
  • 3
  • 19
  • 43