0

I am calling a stored procedure for one request with more than 100 characters in one field and it is getting failed because the field size is 100 and how to split the request for every 100 characters of that particular field? the maximum size for that particular field is 100 and when are passing 250 characters to that field we have to split the call for every 100 characters.

FYI not updating anything into DB just reading the values from DB.

  • 1
    Can you add more details? The stored procedure has a field whose max size is 100, is that why it fails? – raffian May 07 '13 at 02:40
  • 1
    possible duplicate http://stackoverflow.com/questions/2297347/splitting-a-string-at-every-n-th-character – hrezs May 07 '13 at 02:41

2 Answers2

1

You've given very little to go on, but here's my best guess at a solution:

String longStr; // your long string

for (String max100 : longStr.split("(?<=.{,100})")) {
    connection.execute("call someProc('" + max100 + "')");
}

This code is very simplistic and is for illustrative use only. In reality you'd use a prepared statement with placeholders.

That said, the splitting code, which is the core of this question, should be helpful.

Bohemian
  • 412,405
  • 93
  • 575
  • 722
0

Try this:

// longStr is your long string

String substring = null;
PreparedStatement prepped = connection.prepareeStatement("call someProc(?)", ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);

int maxLoop = longStr.length() / 100;
for (int i = 0; i < maxLoop; i++) {
    substring = longStr.substring(100 * i, 100 * (i + 1));
    prepped.setString(1, substring);
    ResultSet result = prepped.executeQuery();
}

if (longStr.length() % 100 != 0) {
    substring = longStr.substring(maxLoop * 100);
    prepped.setString(1, substring);
    ResultSet result = prepped.executeQuery();
}
hd1
  • 33,938
  • 5
  • 80
  • 91