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;
我在MS Access 2013中尝试过此代码,但是如果我在Ireport中为我的报表创建查询时使用相同的代码,则会出现以下错误:
java.sql.SQLException:[Microsoft] [ODBC Microsoft Access Driver] Too 几个参数。预计1。
查询有效如果我只使用一个表,但如果我尝试连接两个表,这就是我得到的:
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)
编辑:我要做的是从表传入和allItems中获取值
以下是我的表格的内容:
allItems:Item_Number [primary],描述 传入:Incoming_ItemNumber [主],ITEM_NUMBER [外国],Date_Incoming,数量,供应商,INVOICE_NUMBER,单价,金额,JO
请注意,我使用的查询在MS ACCESS 2013中正常运行
答案 0 :(得分:0)
在我的代码中经过大量实验后,我想出了自己的解决方案:
1。)我重新 - "链接"我的表关系
2.。)我使用MS Access使用查询设计工具创建了一个新查询 其中:我选择了我需要的表格和数据列并按日期排序
3。)我保存了查询设计并转到了SQL查看'
4.。)我复制了sql查询。
5.)转到我的IReport报告查询并粘贴在那里
然后我点击了“查询查询”。按钮
并且它有效。 这是Access生成的代码:
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;