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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:12:39+00:00 2026-06-17T23:12:39+00:00

I can connect the JDBC driver connect to the database. Break points show it

  • 0

I can connect the JDBC driver connect to the database. Break points show it has a connection id and the fields are properly filled, but after execution of the select statement, no rows are returned even though data is in the database and the SQL call works properly in workbench. It only returns field names without any data.

Why aren’t any rows being returned?

Code:

public class DBConnect {

    private static Connection conn;
    public static String url = "jdbc:mysql://localhost/efwalter";
    public static String user = "root";
    public static String pass = "XXXXXXXXX";
    private PreparedStatement prep;

    public void open_Con() throws ClassNotFoundException {
        try {
            Class.forName("com.mysql.jdbc.Driver");
            conn = DriverManager.getConnection(url, user, pass);
        } catch (SQLException ex) {
            infoBox(ex.toString(), "ERROR");
        }
    }

    public ResultSet get_data(String SQL) {
        try {
            prep = conn.prepareStatement("SELECT * FROM efwalter.impact_tests");
            ResultSet rs = prep.executeQuery();
            return rs;
        } catch (SQLException ex) {
            infoBox(ex.toString(), "ERROR");
            return null;
        }
    }

    public void close_Con() {
        try {
            conn.close();
        } catch (SQLException ex) {
            infoBox(ex.toString(), "ERROR");
        }
    }

    public void infoBox(String infoMessage, String location) {
        JOptionPane.showMessageDialog(null, infoMessage, "InfoBox: " + location, JOptionPane.INFORMATION_MESSAGE);
    }
}

Code where ResultSet is accessed:

 public void searchFired(ActionEvent event) throws ClassNotFoundException {
   try{
        DBConnect db = new DBConnect();
        db.open_Con();
        ResultSet rs = db.get_data();
        db.close_Con();

        while (rs.next())
        {
           study_struct study = new study_struct();
           ObservableList<String> row = FXCollections.observableArrayList();
           study.setStudy_number(rs.getInt(1));
           row.add(rs.getString(1));
           study.setCustomer_id(rs.getInt(2));
           study.setShop_order(rs.getInt(3));
           study.setProduct(rs.getString(4));
           study.setGmax_results(rs.getString(5));
           study.setGmax_average(rs.getDouble(6));
           study.setHic_results(rs.getString(7));
           study.setHic_average(rs.getDouble(8));
           study.setSensor_data_x(rs.getString(9));
           study.setSensor_data_y(rs.getString(10));
           study.setDescription(rs.getString(11));
           study.setGauge(rs.getString(12));
           study.setAppraiser(rs.getString(13));
           study.setStudy_name(rs.getString(14));
           row.add(rs.getString(14));
           study.setTimestamp(rs.getString(15));
           row.add(rs.getString(15));
           study.setWeight(rs.getString(16));
           found_studies.add(study);
           search_table.add(row);
        }

        resultsGrid.setItems(search_table);
   }
   catch (SQLException ex)
   {

   }
}
  • 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-17T23:12:40+00:00Added an answer on June 17, 2026 at 11:12 pm

    Without seeing the code calling your get_data() method, which you should post, I will suspect you need to extract your data from your ResultSet before you close the connection.

    Here is an example of how to work this appropriately:

    http://publib.boulder.ibm.com/infocenter/iseries/v5r3/index.jsp?topic=%2Frzaha%2Fprepex.htm

    EDIT: Based on your newly-posted code:

        DBConnect db = new DBConnect();
        db.open_Con();
        ResultSet rs = db.get_data();
        db.close_Con();
    

    You are closing the connection right after you get the rows, this closes your ResultSet and flushes your data.

    Iterate through the data, THEN call db.close_Con().

    What you really want is a take on this:

    CustomDataContainer data = new CustomDataContainer();
    Connection conn = null;
    PreparedStatement prep = null;
    ResultSet rs = null;
    
    try {
    
        conn = getConnection(); // method returns a connection to your DB
        prep = conn.prepareStatement(STRING_REPRESENTING_YOUR_STATEMENT);
        rs = prep.executeQuery();
    
        while (rs.next()) {
    
           data.addData(rs.getString(1));
        }
    } catch (Exception ex) {
        ex.printStackTrace();
        // re-throw ex
    } finally {
    
        try { rs.close(); } catch (Exception ignore) {}
        try { prep.close(); } catch (Exception ignore) {}
        try { conn.close(); } catch (Exception ignore) {}
    }
    
    return data;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using the embedded driver I can connect to my derby database using the JDBC
Can anyone please tell me to use which jdbc driver to connect with oracle
I can connect manually by doing: M-x sql-postgres and type the User, Database, Host,
To test if i can connect to my database, I execute the following code
In code igniter, you can connect database and make queries in controller like: $this->db->query(Your
can anyone help me how to connect my java forms to my mysql database?
I'm trying to connect to a SQL Server database using JDBC, the database I'm
I want connect to the Oracle database 11.2 with SSL. But the only error
I've been messing around with JDBC and trying to connect to a test database
I have an Oracle database with LDAP, and can connect by writing smth like:

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.