简体   繁体   English

Java-3表内部联接

[英]Java - Inner Join with 3 Table

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, 当我需要将3个表从Microsoft Access内部联接在一起时,会发生问题,

i have no problem to inner join 2 tables together 我没有问题将两个表内部连接在一起

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,我分别为USER | CPU | Software| 3提供一个“ A”表USER | CPU | Software| 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 谢谢

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 不需要','在这里...尝试上面的代码

For Ms Access, when you JOIN more than table, the syntax is different. 对于Access女士,当您JOIN多个表时,语法是不同的。 It should be this way: 应该是这样的:

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) 

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

Problem Solved 问题解决了

For example - 例如 -

Table A | 表A | Username(PK)| 用户名(PK)| Address| 地址|

Table B | 表B | ID | ID | Phone | 电话| Username(FK)| 用户名(FK)|

Table C | 表C | SN | SN | Brand | 品牌| Model | 型号| Username(FK) 用户名(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" 确保必须在Access中链接表关系,然后再运行Java程序,否则它将弹出“ ERROR IN ROW”

Thanks everyone who helping me :) 谢谢所有帮助我的人:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM