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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:59:13+00:00 2026-05-27T18:59:13+00:00

I’m writing an application using the Spring Framework. Description of Exercise: Write a program

  • 0

I’m writing an application using the Spring Framework.

Description of Exercise: Write a program that will let me create a database. The database will contain information about law schools. I can use this to add law schools, query, etc. I am getting an error message stating that my statements don’t generate a Result Set. My code appears to be correct according to my knowledge, but my knowledge is obviously flawed. I am thoroughly convinced that my application.xml file has been written correctly, so I will not include it here.

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.sears.domain.School;

public class SchoolDaoImplementation implements SchoolDao
{
private static final String USERNAME = "sa";
private static final String PASSWORD = "";

private static final String CREATE_TABLE = "CREATE TABLE lawschools (name VARCHAR(15) NOT NULL PRIMARY KEY, city VARCHAR(15), state VARCHAR(2), rank INTEGER)";
private static final String INSERT_SCHOOL = "INSERT INTO lawschools (name, city, state, rank) VALUES (?, ?, ?, ?)";
private static final String SELECT_ALL_SCHOOLS = "GET * FROM lawschools";

private static final String DATABASE_URL = "jdbc:hsqldb:file:database.dat;shutdown=true";
private static final String DRIVER_NAME = "org.hsqldb.jdbcDriver";

public SchoolDaoImplementation()
{
    try
    {
        Class.forName(DRIVER_NAME);
        createTable();
    }
    catch (Exception e)
    {
        throw new RuntimeException(e);
    }
    System.out.println("School DAO implementation instantiated.");
}

private static void createTable()
{
    try
    {
        Connection con = null;
        PreparedStatement createTable = null;
        try
        {
            con = DriverManager.getConnection(DATABASE_URL, USERNAME, PASSWORD);
            createTable = con.prepareStatement(CREATE_TABLE);
            createTable.executeUpdate();
            System.out.println("Creted Table.");
        }
        finally
        {
            if (con != null)
                con.close();
            if (createTable != null)
                createTable.close();
        }
    }
    catch (SQLException e)
    {
        System.out.println("Assuming table has been created.");
    }
    System.out.println("Table created successfully.");
}

public School getSchool(String name)
{
    return null;
}

public List<School> getSchools()
{
    try 
    {
        Connection con = null;
        PreparedStatement selectAllSchools = null;
        ResultSet allSchools = null;
        List<School> schools = new ArrayList<School>();
        try
        {
            con = DriverManager.getConnection(DATABASE_URL, USERNAME, PASSWORD);
            selectAllSchools = con.prepareStatement(SELECT_ALL_SCHOOLS);
            allSchools = selectAllSchools.executeQuery();
            while (allSchools.next())
            {
                String name = allSchools.getString(1);
                String city = allSchools.getString(2);
                String state = allSchools.getString(3);
                int rank = allSchools.getInt(4);
                schools.add(new School(name, city, state, rank));
            }
            return schools;
        }
        finally
        {
            if (con != null)
                con.close();
            if (selectAllSchools != null)
                selectAllSchools.close();
            if (allSchools != null)
                allSchools.close();
        }
    }
    catch (SQLException e)
    {
        throw new RuntimeException(e);
    }
}

public List<School> getByRank(int rank)
{
    return null;
}

public List<School> getByState(String state)
{
    return null;
}

public void addSchool(School newSchool)
{
    try
    {
        Connection con = null;
        PreparedStatement insertSchool = null;
        try
        {
            con = DriverManager.getConnection(DATABASE_URL, USERNAME, PASSWORD);
            insertSchool = con.prepareStatement(INSERT_SCHOOL);
            insertSchool.executeUpdate();
        }
        finally
        {
            if (con != null)
                con.close();
            if (insertSchool != null)
                insertSchool.close();
        }
    }
    catch (SQLException e)
    {
        System.out.println("An error has occured.");
    }
}
}

Client Test:

public class ClientTest 
{
    public static void main(String[] args)
    {
    ApplicationContext container = new ClassPathXmlApplicationContext("application.xml");
    RankingService service = (RankingService) container.getBean("rankingServiceProduction");

    System.out.println("Welcome to the LawSchool Ranking Service\n");

    service.addNewSchool(new LawSchool("Duke", "Durham", "NC", 11));
    service.addNewSchool(new LawSchool("Northwestern", "Chicago", "IL", 11));
    service.addNewSchool(new LawSchool("Cornell", "Ithaca", "NY", 13));
    service.addNewSchool(new LawSchool("Georgetown", "District of Columbia", "DC", 14));        

    List<School> allLawSchools = service.getAllSchools();
    for (School school : allLawSchools)
        System.out.println(school);
}
}

Error Message:

Exception in thread "main" java.lang.RuntimeException: java.sql.SQLException: Statement does not generate a result set
at com.sears.data.SchoolDaoImplementation.getSchools(SchoolDaoImplementation.java:107)
at com.sears.services.RankingServiceProduction.getAllSchools(RankingServiceProduction.java:24)
at com.sears.client.ClientTest.main(ClientTest.java:22)
Caused by: java.sql.SQLException: Statement does not generate a result set
at org.hsqldb.jdbc.Util.sqlException(Unknown Source)
at org.hsqldb.jdbc.Util.sqlException(Unknown Source)
at org.hsqldb.jdbc.jdbcPreparedStatement.checkIsRowCount(Unknown Source)
at org.hsqldb.jdbc.jdbcPreparedStatement.executeQuery(Unknown Source)
at com.sears.data.SchoolDaoImplementation.getSchools(SchoolDaoImplementation.java:84)
    ... 2 more
  • 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-05-27T18:59:14+00:00Added an answer on May 27, 2026 at 6:59 pm

    Try replacing the line

    private static final String SELECT_ALL_SCHOOLS = "GET * FROM lawschools";
    

    with

    private static final String SELECT_ALL_SCHOOLS = "SELECT * FROM lawschools";
    

    or, better still,

    private static final String SELECT_ALL_SCHOOLS = "SELECT name, city, state, rank FROM lawschools";
    

    EDIT: your schools aren’t being populated because you aren’t sending the name, city, state and rank values to the database. Your code for inserting should look something like the following (I don’t have your LawSchool class so I can’t be sure about the names of the get... methods):

        insertSchool = con.prepareStatement(INSERT_SCHOOL);
        insertSchool.setString(1, newSchool.getName());
        insertSchool.setString(2, newSchool.getState());
        insertSchool.setString(3, newSchool.getCity());
        insertSchool.setInt(4, newSchool.getRank());
        insertSchool.executeUpdate();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I'm trying to create an if statement in PHP that prevents a single post
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

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.