I'm running into an odd issue. I have multiple named queries that work as intended. When using certain tables I get an error: com.microsoft.sqlserver.jdbc.SQLServerException: The index 2 is out of range.
Script:
--This is from the query builder and works as intended.
--SELECT Arms_Electronic_Traveler.*
--FROM Arms_Electronic_Traveler
--WHERE Arms_Electronic_Traveler.Arms_Updated_Job_Num = :travelerBarcode
--When I write this I get the error I posted above.
SELECT dbo.Arms_Electronic_Traveler.*
FROM dbo.Arms_Electronic_Traveler
WHERE dbo.Arms_Electronic_Traveler.Arms_Updated_Job_Num = :travelerBarcode
Personally, I think your query should be simplified to this:
SELECT *
FROM Arms_Electronic_Traveler
WHERE Arms_Updated_Job_Num = :travelerBarcode
No need for the table name in everything, and I've never used dbo prefix on anything either.
If you're joining multiple tables, that's where you start needing to use table names, but even then I shorten them to something like this:
SELECT aet.*
FROM Arms_Electronic_Traveler aet
WHERE aet.Arms_Updated_Job_Num = :travelerBarcode
If you really want to include the schema in it, then try this and see if it works:
SELECT aet.*
FROM dbo.Arms_Electronic_Traveler aet
WHERE aet.Arms_Updated_Job_Num = :travelerBarcode
Sometimes the comments can cause issues. Are you leaving that commented query in when you run it?
This gives me the same error:
--SELECT dbo.Asset.*
--FROM dbo.Asset
--WHERE dbo.Asset.ID = :test
SELECT dbo.Asset.*
FROM dbo.Asset
WHERE dbo.Asset.ID = :test
This does not:
--SELECT dbo.Asset.*
--FROM dbo.Asset
--WHERE dbo.Asset.ID = 1
SELECT dbo.Asset.*
FROM dbo.Asset
WHERE dbo.Asset.ID = :test
Specifically, I don't think it likes having the parameter :test in a comment. So if you must keep the commented query, remove :travelerBarcode from the comment.
I believe that is what the issue was. Once I removed the comments, or the parameter from the comment, the issue was no longer present.