Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8311477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T19:49:45+00:00 2026-06-08T19:49:45+00:00

I have the following database ShorthandText textid | text ————————– 1 | just a

  • 0

I have the following database ShorthandText

textid | text
-------------------------- 
1      | just a test
2      | just another test  

I am using the following code to try return the two Strings in the text column

public List<String> executeSQLWithMulipleReturns(String sql) throws SQLException{
    List<String> results = null;
    connection = ConnectDb();
    stat = connection.createStatement();
    resultSet = stat.executeQuery(sql); // sql = "SELECT text FROM ShorthandText;"
    while(resultSet.next()){
        results.add(resultSet.getString(resultSet.getRow()));
        System.out.println(resultSet.toString());
    }

    closeAll(); // closes all connections         
    return results;
}

But am getting the following error

java.sql.SQLException: column 2 out of bounds [1,1]
at org.sqlite.RS.checkCol(RS.java:64)
at org.sqlite.RS.markCol(RS.java:71)
at org.sqlite.RS.getString(RS.java:245)
at Java.ConnectToDatabase.executeSQLWithMulipleReturns(ConnectToDatabase.java:46)
at GUI.ShorthandText.jButton1ActionPerformed(ShorthandText.java:123)
at GUI.ShorthandText.access$000(ShorthandText.java:18)
at GUI.ShorthandText$2.actionPerformed(ShorthandText.java:82)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
at java.awt.Component.processMouseEvent(Component.java:6505)
......

which occurs on this line: results.add(resultSet.getString(resultSet.getRow()));

Can anyone please explain why I am getting this error?

EDIT: Null pointer exception

code

while(resultSet.next()){
        results.add(resultSet.getString("text"));
        System.out.println(resultSet.toString());
    }

while(resultSet.next()){
        results.add(resultSet.getString(1));
        System.out.println(resultSet.toString());
    }

both give this exception

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at Java.ConnectToDatabase.executeSQLWithMulipleReturns(ConnectToDatabase.java:46)
at GUI.ShorthandText.jButton1ActionPerformed(ShorthandText.java:123)
at GUI.ShorthandText.access$000(ShorthandText.java:18)
at GUI.ShorthandText$2.actionPerformed(ShorthandText.java:82)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
.......
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T19:49:47+00:00Added an answer on June 8, 2026 at 7:49 pm

    the problem is here:

    results.add(resultSet.getString(resultSet.getRow()));
    

    resultSet.getString gets as parameter the column index, but you are passing resultSet.getRow()

    if you want to get the ids into results, you should use:

    results.add(resultSet.getString("textid"));
    

    or

    results.add(resultSet.getString(0));
    

    if you want to get the texts into results, you should use:

    results.add(resultSet.getString("text"));
    

    or

    results.add(resultSet.getString(1));
    

    Update

    Oh, my, that’s so simple! You had actually two problems. We already solved the first one. Here’s your second problem:

    List<String> results = null;
    

    The List<String> results has not been initialized, thus, the NullPointerException.’This line should be:

    List<String> results = new ArrayList<String>();
    

    This will take care of it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following text in SQLITE database in TEXT field The exact date of
I have the following database schema (names changed to protect the innocent) Code Table
I have the following database table object: public class Goal { @DatabaseField(generatedId = true)
I have the following database structure. ID | Name | Marks I am trying
I have the following database design: Employee Table: Username, Name, DivisionCode Division Table: SapCode,
I have the following database design: Employee Table: Username, Name Quiz Table: QuizID, Title,
Let's say I have the following database table: record_id | record_date | record_value -----------+-------------+--------------
In PHP, I have following Singleton Database Class: class Database { private static $instance;
I have the following criteria Database should be protected with a username and password.
I have the following MySQL database: |deal_name|price|shop|expiration_date - - - - - - -

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.