Salomao Peixe Salomao Peixe - 2 months ago 10x
Java Question

Unexpected string index out of range exception

When running the following code:

if (loja.length() > 0) {
pstmt2.setString(3, loja.substring(0,68));
} else {
pstmt2.setString(3, "_");

I got this error:

java.lang.StringIndexOutOfBoundsException: String index out of range: 68


loja is shorter than 68 chars: StringOutOfBoundsException is being thrown.