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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T02:25:40+00:00 2026-06-02T02:25:40+00:00

I am trying to add a username into a .accdb local database. My code

  • 0

I am trying to add a username into a .accdb local database. My code is as followed:

try
    {
        String sql = "INSERT INTO Users VALUES('?');";
        System.out.println("SQL : " + sql);

        System.out.println("USER : " + user);

        PreparedStatement stmt = database.prepareStatement(sql);
        System.out.println("Statement : " + stmt);
        stmt.setString(1, user); 
        System.out.println("Statement : " + stmt);

        ResultSet results = stmt.executeQuery(); 
        System.out.println("Results : " + results);
    }
    catch(SQLException sqlEx)
    {
        System.out.println("* Cannot execute insertion! *");
        sqlEx.printStackTrace();
        System.exit(1);
    }

The console output is :

SQL : INSERT INTO Users VALUES('?');
USER : TEST
Statement : sun.jdbc.odbc.JdbcOdbcPreparedStatement@1bf73fa
Exception in thread "Thread-0" java.lang.NullPointerException
at sun.jdbc.odbc.JdbcOdbcPreparedStatement.clearParameter    (JdbcOdbcPreparedStatement.java:1023)
at sun.jdbc.odbc.JdbcOdbcPreparedStatement.setChar    (JdbcOdbcPreparedStatement.java:3057)
at sun.jdbc.odbc.JdbcOdbcPreparedStatement.setString    (JdbcOdbcPreparedStatement.java:766)
at MultiEchoServer.addRegisteredUser(MultiEchoServer.java:100)
at ClientHandler.run(MultiEchoServer.java:339)

Thanks for your help!

  • 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-02T02:25:41+00:00Added an answer on June 2, 2026 at 2:25 am

    This is the problem, I suspect:

    String sql = "INSERT INTO Users VALUES('?');";
    

    That statement doesn’t have any parameters – it will always insert a question mark, because you’ve got it in quotes so it’s a value rather than a parameter. I think you want:

    String sql = "INSERT INTO Users VALUES(?)";
    

    (Note that I’ve removed the extra semi-colon at the end of the SQL statement too – I don’t believe you really want that.)

    It’s unfortunate that the exception isn’t more helpful, admittedly… I’d expect something to indicate that index 1 was out of range.

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

Sidebar

Related Questions

I am trying to add a query in my current SQL INSERT INTO statement.
I am trying to add a query in my current SQL INSERT INTO statement.
I'm trying to insert registration data into a database but my php code isn't
I'm trying to INSERT INTO a mySQL database and I'm getting this error on:
I'm trying to insert variables from an SQL result into a HTML form in
Trying to add a class object into a List using reflection, but when invoking
Im trying to add an element to a database and then return a new
I'm trying to use checkboxes to add users to a specific group but I'm
I am trying to get an insert/return primary key SQL query to run. The
I'm trying to get Entity Framework Code First to create a database for me

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.