[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

What does this error means?

Posted on 2006-07-20
17
Medium Priority
?
252 Views
Last Modified: 2010-03-31
This is my code to access an MS-ACCESS database in java

private static boolean prepareStationCodeNameTable(){
        Statement stmt; // SQL statement object
        String query;   // SQL select string
        ResultSet rs;   // SQL query results

        ArrayList contentTypes = new ArrayList();
        query = "SELECT st-code, st-name from station";
       
        try {
            stmt = con.createStatement();
            rs = stmt.executeQuery(query);
            while(rs.next()){
                stationCodeMap.put(rs.getString("st-code"),rs.getString("st-name"));
            }
            System.out.println("--- Prepared Station Code and Name Map. Total Records are : " + stationCodeMap.size());
            return true;
        }catch(SQLException ex){
            ex.printStackTrace();
        }
        return false;
    }


BUT i am getting this error:

java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 3.
at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6879)
      at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7036)
      at sun.jdbc.odbc.JdbcOdbc.SQLExecDirect(JdbcOdbc.java:3065)
      at sun.jdbc.odbc.JdbcOdbcStatement.execute(JdbcOdbcStatement.java:338)
      at sun.jdbc.odbc.JdbcOdbcStatement.executeQuery(JdbcOdbcStatement.java:253)
      at Import.prepareStationCodeNameTable(Import.java:295)
      at Import.main(Import.java:59)
java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Syntax error in FROM clause.
      at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6879)
      at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7036)
      at sun.jdbc.odbc.JdbcOdbc.SQLExecDirect(JdbcOdbc.java:3065)
      at sun.jdbc.odbc.JdbcOdbcStatement.execute(JdbcOdbcStatement.java:338)
      at sun.jdbc.odbc.JdbcOdbcStatement.executeQuery(JdbcOdbcStatement.java:253)
      at Import.prepareMentorHorizonTable(Import.java:317)
      at Import.main(Import.java:65)


any clue?
0
Comment
Question by:jaipur07
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3
  • 2
  • +2
17 Comments
 
LVL 35

Accepted Solution

by:
girionis earned 672 total points
ID: 17145221
It means that your SELECT statement is not syntactically correct. It is posible that the ODBC bridge does not support all the SQL statements.
0
 

Author Comment

by:jaipur07
ID: 17145233
whats wrong in this select statement? you see it in my post?
0
 
LVL 35

Expert Comment

by:girionis
ID: 17145235
> SELECT st-code, st-name from station

Make sure that you refer to the proper variables and tables in the database.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:jaipur07
ID: 17145238
of course I am there are only 2 fields in this table and i am accesing both
0
 
LVL 35

Expert Comment

by:girionis
ID: 17145241
DO the "st-code" and "st-name" exist in the table "station"? Does the table station exist? Also, not sure if it helps, but what happens if you take the minus signs off the table names?
0
 
LVL 8

Expert Comment

by:hiteshgupta1
ID: 17145257
>>    query = "SELECT st-code, st-name from station";
is ur table name correct??
Can u use  try and catch to know which block is creating error?
0
 
LVL 4

Assisted Solution

by:astorer
astorer earned 664 total points
ID: 17145258
Is "st-code" a valid column name in SQL?  I think it is not.  

the "-" is bad.
0
 
LVL 8

Expert Comment

by:hiteshgupta1
ID: 17145259
ohhhh
u r already using try and catch!!
0
 
LVL 35

Expert Comment

by:girionis
ID: 17145263
Also check if the path of the database you are accessing contains a dot (".").

http://support.microsoft.com/kb/171899/
0
 

Author Comment

by:jaipur07
ID: 17145275
i tried select * from station
and then i am getting values like

String code = rs.getString("st-code");

working fine nowwww
0
 
LVL 35

Expert Comment

by:girionis
ID: 17145298
This SELECT st-code, st-name from station should also work.
0
 
LVL 92

Assisted Solution

by:objects
objects earned 664 total points
ID: 17145326
try:

        query = "SELECT [st-code], [st-name] from station";
0
 
LVL 4

Expert Comment

by:astorer
ID: 17145376
> SELECT st-code, st-name from station should also work.

No it shouldn't in standard SQL.  What you are asking for is values for
  st minus code
  st minus name

Access may allow you to define such column names but grown up databases would not.
0
 
LVL 35

Expert Comment

by:girionis
ID: 17145402
If they are defined I cannot see why they cannot be accessed. If they are not to be accessed then why does a databaselet you define them?
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question