This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes JDBC and the fly likes Invalid column index -- SQL Exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Invalid column index -- SQL Exception" Watch "Invalid column index -- SQL Exception" New topic
Author

Invalid column index -- SQL Exception

Rajesh Kumar Sm
Greenhorn

Joined: Dec 15, 2010
Posts: 2
Hi All,

When i run my java program i am getting the Invalid column index error. But it looks the columns in the query and the code accessing the resultset data are proper. Please look into the below and provide your suggestions to nail down the issue,

Query:
SELECT DISTINCT a.customer,'*****' AS "ORDER_NUMBER",b.cust_po_num,b.cust_line_item,DECODE(b.mkt_part_num,'',b.cus_part_num),b.cr_qty,'$'||b.locunitprice,TO_CHAR(b.cr_date), 'PreGated' FROM XXCYP_OE_ORDER_EDI850_TMP a, XXCYP_OE_ORDER_EDI850_HIST b, XXCYP_OE_ORDER_EDI850_FALLOUT c WHERE a.cust_po_num=b.cust_po_num AND a.cust_po_num=c.cust_po_num AND b.cust_po_num=c.cust_po_num AND a.customer =? ORDER BY b.cust_po_num,b.cust_line_item

Code:

String body = body + rsOrdInfoGated.getString(2) + fillSpaces(12,rsOrdInfoGated.getString(2).length())
+ rsOrdInfoGated.getString(3) + fillSpaces(16,rsOrdInfoGated.getString(3).length())
+ rsOrdInfoGated.getString(4) + fillSpaces(11,rsOrdInfoGated.getString(4).length())
+ rsOrdInfoGated.getString(5) + fillSpaces(25,rsOrdInfoGated.getString(5).length())
+ fillSpaces(8,rsOrdInfoGated.getString(6).length()) + rsOrdInfoGated.getString(6)
+ fillSpaces(10,rsOrdInfoGated.getString(7).length()) + rsOrdInfoGated.getString(7)
+ fillSpaces(12,rsOrdInfoGated.getString(8).length()) + rsOrdInfoGated.getString(8)
+ fillSpaces(10,rsOrdInfoGated.getString(9).length()) + rsOrdInfoGated.getString(9)
+ "\n\n";

Thanks in advance.

Regards,
Rajesh.
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2497
    
    8

I haven't counted , but not all drivers support that you call the getXXX() twice for the same column.
Why don't you temporary put each call on a separate line, so that the error will show which call is bogus?

I mean:



OCUP UML fundamental and ITIL foundation
youtube channel
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2497
    
    8

... and welcome to the Ranch!
Rajesh Kumar Sm
Greenhorn

Joined: Dec 15, 2010
Posts: 2
Hi Jan,

Thanks for your response, will try this out.

Regards,
Rajesh.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Invalid column index -- SQL Exception