FookShen
FookShen

Reputation: 9

Java - Inner Join with 3 Table

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

The problem occur when i need to inner join 3 tables together from 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

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|

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

Thanks

Upvotes: 0

Views: 17767

Answers (4)

FookShen
FookShen

Reputation: 9

Problem Solved

For example -

Table A | Username(PK)| Address|

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

Table C | SN | Brand | Model | Username(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.

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

Thanks everyone who helping me :)

Upvotes: 0

Mahmoud Gamal
Mahmoud Gamal

Reputation: 79929

For Ms Access, when you JOIN more than table, the syntax is different. 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) 

Upvotes: 2

DINESH4DINA
DINESH4DINA

Reputation: 45

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

Upvotes: 3

stinepike
stinepike

Reputation: 54672

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

Upvotes: 1

Related Questions