Results 1 to 3 of 3
  1. #1
    waqashaider is offline Member
    Join Date
    May 2012
    Posts
    4
    Rep Power
    0

    Default java.lang.StringIndexOutofBoundsException:String Index out of range : -1

    public class ResultSetEx
    {

    public static void main (String args[])
    {
    try
    {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); //load driver
    String url = "jdbc:odbc:personDSN";// define connection
    Connection con = DriverManager.getConnection(url); //establish connection
    String sql = "SELECT*FROM Person";
    PreparedStatement pStmt = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INS ENSITIVE,ResultSet.CONCUR_UPDATABLE);//create statement
    ResultSet rs = pStmt.executeQuery();
    rs.next();
    System.out.println("moving cursor forward");
    String name = rs.getString("Name");
    System.out.println(name);
    rs.next();
    rs.previous();
    name = rs.getString("Name");
    System.out.println(name);
    con.close();
    }
    catch(Exception sqlEx)
    {
    System.out.println(sqlEx);
    }

    }}

  2. #2
    waqashaider is offline Member
    Join Date
    May 2012
    Posts
    4
    Rep Power
    0

    Default Re: java.lang.StringIndexOutofBoundsException:String Index out of range : -1

    Whats is the problem with my code here.
    Please help in rectifying it regards

    Waqas

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,372
    Blog Entries
    7
    Rep Power
    25

    Default Re: java.lang.StringIndexOutofBoundsException:String Index out of range : -1

    Change your last line with real code to:

    Java Code:
    sqlEx.printStackTrace();
    ... so you can see where the error was detected.

    kind regards,

    Jos
    The only person who got everything done by Friday was Robinson Crusoe.

Similar Threads

  1. String index out of range: -1 Error.
    By ashishb4 in forum New To Java
    Replies: 12
    Last Post: 09-28-2011, 07:32 PM
  2. Replies: 3
    Last Post: 09-11-2011, 09:15 AM
  3. String index out of range: -1 due to length function
    By ashishb4 in forum New To Java
    Replies: 1
    Last Post: 06-03-2011, 07:04 AM
  4. Replies: 2
    Last Post: 01-07-2011, 12:50 PM
  5. String index out of range: -1 Please Help
    By davetheant in forum New To Java
    Replies: 22
    Last Post: 09-11-2010, 12:32 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •