Mahi Mali
Mahi Mali

Reputation: 111

In Spring, queryForList Function of jdbcTemplate Returning as object causes NumberFormatException

I am using Spring JDBCTemplate as below,

List<Map<String, Object>> ordersList = new ArrayList<Map<String,Object>>();

String sql = "SELECT aa.Barcode, aa.ItemName, aa.Quantity AS Qty\n" +
                    "FROM\n" +
                    "(SELECT Barcode, ItemName, Quantity\n" +
                    "FROM PurchaseDetails\n" +
                    "UNION\n" +
                    "SELECT Barcode, ItemName, Quantity\n" +
                    "FROM BarcodePrinting) aa";
System.out.println(sql);

jdbcTemplate = new JdbcTemplate(dataSource);
ordersList = jdbcTemplate.queryForList(sql);

System.out.println("ordersList= "+ordersList.toString());

In Result of above code System Printed As,

SELECT aa.Barcode, aa.ItemName, aa.Quantity AS Qty
FROM
(SELECT Barcode, ItemName, Quantity
FROM PurchaseDetails
UNION
SELECT Barcode, ItemName, Quantity
FROM BarcodePrinting) aa
ordersList= [{Barcode=8901030627330, ItemName=Lux Soft Touch, Qty=[B@72d4ef0c}, {Barcode=8901396393511, ItemName=Dettol org, Qty=[B@799a37b9}]

So, insted of Integer Return it Returns as

[B@72d4ef0c

But Before, I have tried this query in database and it returns correct numbers as expected.

Please help me.

Upvotes: 0

Views: 546

Answers (1)

shazin
shazin

Reputation: 21883

[B@72d4ef0c

Means it is a byte array. Try changing your SQL as follows

String sql = "SELECT aa.Barcode, aa.ItemName, SUM(aa.Quantity) AS Qty\n" +
                    "FROM\n" +
                    "(SELECT Barcode, ItemName, Quantity\n" +
                    "FROM PurchaseDetails\n" +
                    "UNION\n" +
                    "SELECT Barcode, ItemName, Quantity\n" +
                    "FROM BarcodePrinting) aa\n " +
                    "GROUP BY aa.Barcode, aa.ItemName";

Upvotes: 1

Related Questions