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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:57:52+00:00 2026-06-13T02:57:52+00:00

I want to insert values to my database table made in ms access. This

  • 0

I want to insert values to my database table made in ms access. This code works before and I can’t understand why it gets some error now.

Exception in thread "main" java.lang.NullPointerException
at storeapp.Trylog.<init>(Trylog.java:28)
at storeapp.Trylog.main(Trylog.java:45)

I believe I configured the driver correctly.

I have a table name ACCOUNT with columns Username and Password..

And here is the code…..

public class Trylog extends JFrame{
Connection con;
Statement st;
ResultSet rs;

public Trylog(){
    connect();

    String u = "Katherine";
    String p = "kat";

    String sql = "Insert into ACCOUNT(Username, Password) Values ('"+u+"' , '"+p+"' ) ";
    try {
        rs = st.executeQuery(sql);
    } catch (SQLException ex) {
    }
}

public void connect(){
    try {
            String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
             Class.forName(driver);
             String db = "jdbc:odbc:access";
             con = DriverManager.getConnection(db);
             st = con.createStatement();
    }
    catch (Exception ex){}
}

public static void main(String[] args) {
    Trylog r = new Trylog();
    r.setVisible(true);
    r.setSize(600, 800);
    r.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

}

Do anyone know why I get such error?

This is the line that cause the exception base from line 28 and 46

rs = st.executeQuery(sql);

and

 Trylog r = new Trylog();

It prints

Exception in thread "main" java.lang.RuntimeException: java.sql.SQLException: No ResultSet was produced

Caused by: java.sql.SQLException: No ResultSet was produced

  • 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-13T02:57:53+00:00Added an answer on June 13, 2026 at 2:57 am

    Your concrete problem is caused by bad exception handling (even more, there’s no exception handling at all). You’ve there catch blocks which completely swallows the exception, such as here:

    catch (Exception ex){}
    

    This way the code continues to run in case of an exception, possibly leaving the variables in the try block such as st uninitialized. After that, those uninitialized (i.e. they are still null) variables are been accessed which in turn causes the NullPointerException.

    This shouldn’t happen. When an exception is caught, the code should properly deal with it. In this case, it should stop immediately and show the error detail in some way. At this moment, easiest is to rethrow it as a runtime exception so that you will at least get all the necessary information about the problem:

    catch (Exception ex) { 
        throw new RuntimeException(ex);
    }
    

    (you can always improve this by logging the stacktrace and showing some user friendly message dialog and then exiting the program, for example)

    The thrown exception is basically the whole answer to the root cause of your problem. The art is to be able to interpret and understand the stacktrace.


    Update as per your update, you got

    java.sql.SQLException: No ResultSet was produced
    

    See, there’s your answer! There’s no ResultSet been produced at all for the given query, while you expected it to be produced. And indeed, an INSERT query won’t return a result set. It will at highest return the amount of affected rows.

    You need to replace

    rs = st.executeQuery(sql);
    

    by

    st.executeUpdate(sql);
    

    See also the executeQuery() javadoc and the executeUpdate() javadoc. They precisely tell for which SQL statements the method should be used.

    executeQuery

    Executes the given SQL statement, which returns a single ResultSet object.

    Parameters:
    sql – an SQL statement to be sent to the database, typically a static SQL SELECT statement

    executeUpdate

    Executes the given SQL statement, which may be an INSERT, UPDATE, or DELETE statement or an SQL statement that returns nothing, such as an SQL DDL statement.

    Parameters:
    sql – an SQL Data Manipulation Language (DML) statement, such as INSERT, UPDATE or DELETE; or an SQL statement that returns nothing, such as a DDL statement.

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

Sidebar

Related Questions

I have the following code below which works, but I want to insert values
How can insert values on input in database mysql by json_encode and foreach, this
I made iPad application in which, I want to insert record into database table,
I have made some statistics which I want to insert into database to see
I want to insert some session data in a database. I have one table
I have the following table: I want to insert values from the MySQL workbench.
i want to insert the values of two arrays into a table in a
I have an entity Report whose values I want to insert into a database
I have some code that links to Access and works fine with adodbapi, except
i want to insert data into sql server Compact edition the database table screenshot

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.