I have three tables firm
, shipp
and supplier
.
all three columns have same column names as id
, name
, city
... other.
And I have written a join like in java:
String Query = "SELECT s.name Sname,s.city Scity,f.name Fname,f.city Fcity,"
+"su.name Suname,su.city Sucity "
+"FROM `order_details` ot "
+"INNER JOIN `order` o ON ot.odr_id = o.odr_id "
+"INNER JOIN `product` p ON ot.pro_id = p.id "
+"INNER JOIN `firm` f ON o.firm_id = f.id "
+"INNER JOIN `shipp` s ON o.shipp_id = s.id "
+"INNER JOIN `supplier` su ON o.sup_id = su.id ";
product
,order
and order_details
are the other tables that are used in join.
This query working in phpMyAdmin.
But in java ResultSet
giving "column 'Sname' not found." error.
I have tried below solutions but these are not working for me:
1) java.sq.SQLException: Column not found
2) Strange SQLException: Column not found
3) Many other but no one working
Error Stack:
java.sql.SQLException: Column 'Sname' not found.
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1074)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:988)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:974)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:919)
And:
SEVERE: null
Please help me!
Thanks In advance.
Edit 1:
Problem Reproduce:
When I run it with fetching data only from one aliased table (e.g. shipp
) then it fetches data fine:
SELECT s.name Sname,s.city Scity ... other query part
But as soon as I SELECT
columns from other aliased tables (e.g. shipp
, firm
, and supplier
) then it throws error exception written above (Column not found).
SELECT s.name Sname,s.city Scity,f.name Fname,f.city Fcity,
su.name Suname,su.city Sucity ... other query part
Note: This query running fine in phpmyadmin but not running with ResultSet
fetch.
And this is how I'm getting columns from ResultSet
(rs2
):
String firstColumn = "";
String secondColumn = "";
while(rs2.next()) {
firstColumn = "Shipp to : ";
firstColumn += rs2.getString("Sname") + rs2.getString("Scity") ;
firstColumn += "Person : " + rs2.getString("Fname") +"+ "+ rs2.getString("Fcity");
secondColumn = "Supplier : " + rs2.getString("Suname");
secondColumn += rs2.getString("Suname");
secondColumn += rs2.getString("Sucity");
}