Java - 带有 3 个表的内部连接

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20853630/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 04:48:30  来源:igfitidea点击:

Java - Inner Join with 3 Table

javasqlms-access-2007inner-join

提问by FookShen

i doing some project using Java(netbeans sw) and link to Microsoft Access.

我使用 Java(netbeans sw) 做一些项目并链接到 Microsoft Access。

The problem occur when i need to inner join 3 tables together from Microsoft Access,

当我需要从 Microsoft Access 将 3 个表内部连接在一起时会出现问题,

i have no problem to inner join 2 tables together

我没有问题将 2 个表内连接在一起

rsUpdate = 

stmtUpdate.executeQuery("SELECT * FROM A_User Inner Join A_PC ON A_USER.SN = A_PC.SN");

which i able to get the result. But not inner join with 3 tables

我能够得到结果。但不是与 3 个表的内部连接

rsUpdate = 

stmtUpdate.executeQuery

("SELECT * FROM A_User Inner Join A_CPU ON A_USER.SN = A_CPU.SN , Inner Join A_Software ON A_CPU.SN = A_Software.SN")

For the SQL above I have 3 "A" table separately for USER | CPU | Software|

对于上面的 SQL,我分别有 3 个“A”表 USER | CPU | Software|

USER PK is SN | CPU FK is SN | Software PK is SN | 

The Error I got java.sql.SQLException:Characters found after end SQL statement

我得到的错误 java.sql.SQLException:Characters found after end SQL statement

Thanks

谢谢

回答by stinepike

There should be no comma after the first join

第一次加入后不应该有逗号

rsUpdate = 

stmtUpdate.executeQuery

("SELECT * FROM A_User Inner Join A_CPU ON A_USER.SN = A_CPU.SN  Inner Join A_Software ON A_CPU.SN = A_Software.SN")

回答by Mahmoud Gamal

For Ms Access, when you JOINmore than table, the syntax is different. It should be this way:

对于 Ms Access,当你JOIN多于表时,语法是不同的。应该是这样的:

SELECT * 
FROM   ((a_user 
         INNER JOIN a_cpu 
                 ON a_user.sn = a_cpu.sn) 
        INNER JOIN a_software 
                ON a_cpu.sn = a_software.sn) 

回答by DINESH4DINA

rsUpdate = 

stmtUpdate.executeQuery

("SELECT * FROM A_User
Inner Join A_CPU ON A_USER.SN = A_CPU.SN
Inner Join A_Software ON A_CPU.SN = A_Software.SN");

no need for ',' here... try this above code

这里不需要“,”...试试上面的代码

回答by FookShen

Problem Solved

问题解决了

For example -

例如 -

Table A | Username(PK)| Address|

表A | 用户名(PK)| 地址|

Table B | ID | Phone | Username(FK)|

表 B | 身 | 电话 | 用户名(FK)|

Table C | SN | Brand | Model | Username(FK)

表 C | SN | 品牌 | 型号 | 用户名(FK)

rs = st.executeQuery

("SELECT * FROM (A Inner Join B on A.Username = B.Username) Inner Join C on A.Username = C.Username");

if anyone looking for inner join 3 tables together by Using JAVA and Link to Access use the referenece above.

如果有人通过使用 JAVA 和 Link to Access 寻找内部连接 ​​3 个表,请使用上面的引用。

Make sure you must link the table relationship in Access before run the java program if not it will pop out "ERROR IN ROW"

确保你必须在运行java程序之前链接Access中的表关系,否则它会弹出“ERROR IN ROW”

Thanks everyone who helping me :)

感谢所有帮助我的人:)