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

  • Home
  • SEARCH
  • 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 8942871
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:37:55+00:00 2026-06-15T11:37:55+00:00

Here is a method that I am writing for a class. It is supposed

  • 0

Here is a method that I am writing for a class. It is supposed to refresh a table with data obtained from quering a database. I get an error when trying to scan through the line newResult.next().

I tried debugging, but that doesn’t show me anything. the code prints out the line “In while loop”, so I know that the problem is the in the line right after it. I constantly get the error, “After start of result set”. I tried looking at my code, but it doesn’t look like I am calling that method anywhere else either. thanks.

public void refresh()
{

try
{

   Statement statement = gtPort.getConnection().createStatement();
   //this query is also not working, not really sure how it works.              
   String query = "SELECT CRN, Title, Instructor, Time, Day, Location, Letter"
                      + "FROM Section S WHERE CRN NOT IN " 
                      + "(SELECT CRN FROM Registers R WHERE Username = \""
                      + gtPort.userName + "\")";

    System.out.println(query);
    statement.executeQuery(query);
    System.out.println("Statemetne execute ");

    // String[] columns = {"Select", "CRN", "Title",  "Instructor",  "Time",
    // "Days", "location", "Course Code*", "Section"*,"Mode of Grading*"};  

    ResultSet result = statement.getResultSet();

    System.out.println("created result");
    data = new Object[10][10];

    System.out.println("created data");
    Object[] values = new Object[10];

    System.out.println("created values");
    //  values[0] = null;

    if (result == null)
    {
        System.out.println("result is null");
    }

    String[] titles = new String[100];

    //for (int i = 1; i< table.getColumnCount(); i++)
    //model.removeRow(i);

    //table.removeAll();
    //table.repaint()
    model.setRowCount(0);
    table = new JTable(model);

    model.setRowCount(35);
    for (int i = 1; result.next(); i++)
    {
        values[1] = Boolean.FALSE; 
        for (int j = 2; j< 8; j++)
        values[j] = result.getString(j); 

        titles[i] = result.getString(2);
                model.insertRow(i, values);

    }

    String[] codes = new String[table.getColumnCount()];
    System.out.println("count: " + titles.length);

    for (int i = 1; I < titles.length; i++)
    {
        query = new String("SELECT C.Code FROM Code C WHERE C.Title = \""
                        + titles[i] + "\"");
        //this is a different query to check for titles.        
        statement.executeQuery(query);

        System.out.println(query);
        ResultSet newResult = statement.getResultSet();
        //  codes[i] =  newResult.getString(1);

        if (newResult == null)
        {   
            System.out.println("it is null");
            break;
        }
        //this is the loop where it breaks.     
        while(newResult.next());
        {
            System.out.println("in while loop");
                    //this line prints, so the next line must be the problem.                       
            model.setValueAt(newResult.getString(1), i, 8);


        }

        System.out.println("nr: \t" +newResult.getString(1));           
    }       

    System.out.println("before table");
    table = new JTable(model);

    System.out.println("created table");

    }   

    catch (Exception exe)
    {
        System.out.println("errored in course selection");
        System.out.println(exe);
    }
}
  • 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-15T11:37:56+00:00Added an answer on June 15, 2026 at 11:37 am
    1. Write ResultSet rs = statement.executeQuery(query); instead. getResultSet() is called when you have got more then one result sets from executed statement.
    2. Don’t use constructor new String() for creating String. Simply write:
      String new = "content";
    3. You cannot predict how much your first query will return so don’t create arrays with stated size but use better ArrayList:

    Code:

    //creation
    List<Object> values = new ArrayList<Object>();
    List<String> titles = new ArrayList<String>();
    //usage - adding
    values.add(someObject);
    //usage - getting
    for (String title : titles)
    //or
    titles.get(byIndex);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a class that have a method of removing an object from other
I call addNotify() method in class that I posted here. The problem is, that
I am writing a program that reads data packets from a file, and assigns
Here is the question: write a method that swaps two variables. These two variables
Just a quick newbie question here. I have a method that calculates a value
The method in question that I want to use is gem and sourced here
Introduction I am aware that "user-defined conversions to or from a base class are
I'm writing very basic schema-based Spring AOP, here's the .xml <bean id=aoplistener class=tao.zhang.Listener/> <aop:config>
I am writing a simulation of Bananagrams. Currently, I have a GameMaster class that
It is known that in Ruby, class methods get inherited: class P def self.mm;

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.