Mani
Mani

Reputation: 1374

java sql exception syntax error in from clause

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.

Upvotes: 0

Views: 1318

Answers (3)

D.R.
D.R.

Reputation: 21224

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]

Upvotes: 2

Balayesu Chilakalapudi
Balayesu Chilakalapudi

Reputation: 1406

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));

Upvotes: 0

bobbel
bobbel

Reputation: 3365

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.

Upvotes: 3

Related Questions