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 9118821
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:14:47+00:00 2026-06-17T05:14:47+00:00

I’m working on my homework and I can’t complete one piece of my program

  • 0

I’m working on my homework and I can’t complete one piece of my program …

I have JTable class which makes table in my code … i have to write method which takes information from sql database and writes it in list

method MUST look like:

public static List selectAnswers (int questionId) throws SQLException, IOException

following code is written by me:

public static List<AnswerRow> selectAnswers (int questionId) throws SQLException, IOException
{
    Connection veza = connectToDatabase();

    Properties query = new Properties();

    AnswersTableModel atm = new AnswersTableModel();

    String selectAnswers = query.getProperty("selectAnswers");

    PreparedStatement preparedStatement = veza.prepareStatement(selectAnswers);

    ResultSet rs = preparedStatement.executeQuery();

    List<AnswerRow> lista = new ArrayList<AnswerRow>();

    while(rs.next()){

        String answerText = rs.getString("answerText");
        boolean isRight = rs.getBoolean("answerRight");

                    ?????????????????????????????????????????????????


    }

    closeConnectionToDatabase(veza);

    return lista;
}

????? field is missing and i dont know what to write there to write information answeText and isRight into AnswerRow class , into AnswerTableModel, into list …

Code which makes JTable (and is given to me and cannot be changed by my teacher) is here:

package hr.tvz.java.deveti.model;

import java.util.List;
import java.util.ArrayList;

import javax.swing.table.AbstractTableModel;

public class AnswersTableModel extends AbstractTableModel {

    private Object[][] answers;
    private String[] columnNames;

    public AnswersTableModel (String[] colNames){
        super();
        columnNames = colNames;
    }

    public AnswersTableModel() {
        super();
        this.columnNames = new String[AnswerRow.TABLE_COLUMNS];
        this.columnNames[0] = "Odgovor";
        this.columnNames[1] = "Točan/Netočan";
    }

    public java.lang.Class<?> getColumnClass(int columnIndex) {
        return getValueAt(0, columnIndex).getClass();
    }

    public int getColumnCount() {
        return AnswerRow.TABLE_COLUMNS;
    }

    public int getRowCount() {
        if (answers != null)
            return answers.length;
        else
            return 0;
    }

    public Object getValueAt(int row, int column) {
        return answers[row][column];
    }

    public String getColumnName(int column){
        return columnNames[column];
    }

    public void setValueAt (Object aValue, int rowIndex, int columnIndex){
        answers[rowIndex][columnIndex] = aValue;
    }

    public boolean isCellEditable (int rowIndex, int columnIndex){
        return true;
    }

    public void addNewRow(){
        Object[] o = new Object[] {"", false};
        if ((answers == null) || (answers.length == 0)) {
            answers = new Object[][] {o};
        }else{
            Object[][] answersTemp = new Object[answers.length + 1][AnswerRow.TABLE_COLUMNS];
            for (int i = 0; i < answers.length; i++)
                answersTemp[i] = answers[i];
            answersTemp[answersTemp.length - 1] = o;
            answers = answersTemp;
        }
    }

    public List<AnswerRow> getAnswerRows() {
        List<AnswerRow> list = new ArrayList<>();
        for (Object[] oRow : answers) {
            AnswerRow row = new AnswerRow();
            row.setAnswer((String) oRow[0]);
            row.setRight((boolean) oRow[1]);
            list.add(row);
        }

        return list;
    }

    public void setAnswerRows(List<AnswerRow> answerRows){
        if (answerRows.size() == 0 ) {
            this.answers = new Object[0][0];
            return;
        }
        this.answers = new Object[answerRows.size()][AnswerRow.TABLE_COLUMNS];
        for (int i = 0; i < answers.length; i++){
            answers[i][0] = answerRows.get(i).getAnswer();
            answers[i][1] = answerRows.get(i).isRight();
        }
        this.columnNames = new String[AnswerRow.TABLE_COLUMNS];
        this.columnNames[0] = "Odgovor";
        this.columnNames[1] = "Točno/Netočno";
    }

    public class AnswerRow {
        public static final int TABLE_COLUMNS = 2;
        private boolean isRight;
        private String answer;

        public AnswerRow(){
            answer = "";
            isRight = false;
        }

        public AnswerRow(String answer, boolean isRight){
            this.answer = answer;
            this.isRight = isRight;
        }

        public String getAnswer() {
            return answer;
        }

        public void setAnswer(String answer){
            this.answer = answer;
        }

        public boolean isRight(){
            return isRight;
        }

        public void setRight(boolean isRight){
            this.isRight = isRight;
        }
    }
}

Please help me .. thanks !

  • 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-17T05:14:48+00:00Added an answer on June 17, 2026 at 5:14 am
    List<AnswerRow> lista = new ArrayList<AnswerRow>();
    
        while(rs.next()){
    
            String answerText = rs.getString("answerText");
            boolean isRight = rs.getBoolean("answerRight");
    
            //Create AnswerRow instance and set values to it and Add it to list.
            AnswersTableModel .AnswerRow ansrow = atm.new AnswerRow();
            ansrow.setAnswer(answerText);
            ansrow.setRight(isRight);
    
           //Add it to list.
           lista.add(ansrow);
        }
    

    One thing I am not sure is why you have AnswersTableModel and what you do with that.

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

Sidebar

Related Questions

I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have an autohotkey script which looks up a word in a bilingual dictionary
I have an array which has BIG numbers and small numbers in it. I
I have a text area in my form which accepts all possible characters from
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is

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.