Salomao Peixe Salomao Peixe - 1 year ago 130
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

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download