MS Access: The issue with INNER JOIN

641 views Asked by At
 SELECT  
   Incoming.`Incoming_ItemNumber` AS ItemNumber,
   Incoming.`Date_Incoming` AS 'Date',
   allItems.`Description` , Incoming.`Quantity` ,
   Incoming.`Supplier` , Incoming.`Invoice_Number` ,
   Incoming.`Price` , Incoming.`JO` 
FROM 
   allItems 
INNER JOIN 
   Incoming ON allItems.Item_Number = Incoming.Item_Number;

I've Tried this code in MS access 2013 and it is working however if I use this same code in creating a query for my report in Ireport I get the following error:

java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1.

The query works If I am using just one table but if I try to join two tables this is what I get:

Query error


Message:
    net.sf.jasperreports.engine.JRException: java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1.
Level:
    SEVERE
Stack Trace:
java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1.
    com.jaspersoft.ireport.designer.data.fieldsproviders.SQLFieldsProvider.getFields(SQLFieldsProvider.java:174)
    com.jaspersoft.ireport.designer.connection.JDBCConnection.readFields(JDBCConnection.java:472)
    com.jaspersoft.ireport.designer.wizards.ConnectionSelectionWizardPanel.validate(ConnectionSelectionWizardPanel.java:146)
    org.openide.WizardDescriptor$7.run(WizardDescriptor.java:1357)
    org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:572)
    org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:997)

[Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1.
    sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6964)
    sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7121)
    sun.jdbc.odbc.JdbcOdbc.SQLExecute(JdbcOdbc.java:3156)
    sun.jdbc.odbc.JdbcOdbcPreparedStatement.execute(JdbcOdbcPreparedStatement.java:215)
    sun.jdbc.odbc.JdbcOdbcPreparedStatement.executeQuery(JdbcOdbcPreparedStatement.java:90)
    net.sf.jasperreports.engine.query.JRJdbcQueryExecuter.createDatasource(JRJdbcQueryExecuter.java:233)
    com.jaspersoft.ireport.designer.data.fieldsproviders.SQLFieldsProvider.getFields(SQLFieldsProvider.java:126)
    com.jaspersoft.ireport.designer.connection.JDBCConnection.readFields(JDBCConnection.java:472)
    com.jaspersoft.ireport.designer.wizards.ConnectionSelectionWizardPanel.validate(ConnectionSelectionWizardPanel.java:146)
    org.openide.WizardDescriptor$7.run(WizardDescriptor.java:1357)
    org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:572)
    org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:997)

EDIT:What I am Trying to do is to get the Values from Tables Incoming and allItems

Here is the content of my tables:

allItems:Item_Number[primary], Description Incoming:Incoming_ItemNumber[Primary],Item_Number[foreign],Date_Incoming,Quantity,Supplier,Invoice_Number,Price,Amount,JO

note that the Query I am using is working fine in MS ACCESS 2013

1

There are 1 answers

0
Kym NT On BEST ANSWER

After a lot of experimenting in my code, I came up with my own solution:

1.) I re-"linked" my table relationships

2.) I created a new query using the Query Design Tool using MS Access in which: I selected the tables and data columns I need and sorted it by date

3.) I saved the Query Design and went to 'SQL View'

4.) I Copied the sql query.

5.) went to my IReport's Report Query and pasted it there

Then I clicked 'Read Query' button

and It worked. Here is the Access generated code:

SELECT 
   allItems.Item_Number,
   Incoming.Date_Incoming,
   allItems.Description,
   Incoming.Quantity, 
   Incoming.Supplier,
   Incoming.Invoice_Number,
   Incoming.Price,
   Incoming.Amount,
   Incoming.JO
FROM 
   allItems 
RIGHT JOIN 
   Incoming 
ON 
   allItems.Item_Number = Incoming.Item_Number
ORDER BY 
   Incoming.Date_Incoming ASC;