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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:32:04+00:00 2026-05-25T12:32:04+00:00

I wrote following java method and when I call it, gives me the error

  • 0

I wrote following java method and when I call it, gives me the error

Parameter index out of range (2 > number of parameters, which is 1).

Can anyone please explain me what’s wrong with my code?

Thanks a lot in advance!

here is the code

private void updateTskUserEmail( Connection hrmsCon ) throws SQLException
{
    ResultSet rsUserEmailMap = null;

    PreparedStatement ps = null;
    PreparedStatement psEmail = null;


    for ( String lbUserEmail : lbUserList )
    {

        try
        {
            String query = "SELECT * FROM tsk_user WHERE email=? ";

            int count = 0;
            ps = hrmsCon.prepareStatement( query );

            if ( lbUserEmail == null )
            {
                ps.setNull( ++count, java.sql.Types.VARCHAR );
            }
            else
            {
                ps.setString( ++count, lbUserEmail );
            }

            rsUserEmailMap = ps.executeQuery();
            while ( rsUserEmailMap.next() )
            {
                String queryInsert = "INSERT INTO tsk_user_email (";
                queryInsert += "user_email,";
                queryInsert += "user_id)";
                queryInsert += " VALUES(?,?) ON DUPLICATE KEY UPDATE user_id=? ";

                int countInsert = 0;
                psEmail = hrmsCon.prepareStatement( query );

                if ( lbUserEmail == null )
                {
                    psEmail.setNull( ++countInsert, java.sql.Types.VARCHAR );
                }
                else
                {
                    psEmail.setString( ++countInsert, lbUserEmail );
                }
                psEmail.setInt( ++countInsert, rsUserEmailMap.getInt( "user_id" ) );
                psEmail.setInt( ++countInsert, rsUserEmailMap.getInt( "user_id" ) );

                psEmail.execute();

            }
        }
        finally
        {
            if ( ps != null )
            {
                ps.close();
            }
            if ( rsUserEmailMap != null )
            {
                rsUserEmailMap.close();
            }
            psEmail.close();
        }
    }

}

full stack trace

java.sql.SQLException: Parameter index out of range (2 > number of parameters, which is 1).
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1075)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:989)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:984)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:929)
    at com.mysql.jdbc.PreparedStatement.checkBounds(PreparedStatement.java:3711)
    at com.mysql.jdbc.PreparedStatement.setInternal(PreparedStatement.java:3695)
    at com.mysql.jdbc.PreparedStatement.setInternal(PreparedStatement.java:3737)
    at com.mysql.jdbc.PreparedStatement.setInt(PreparedStatement.java:3681)
    at it.codegen.LbEmailMapper.updateTskUserEmail(LbEmailMapper.java:155)
    at it.codegen.LbEmailMapper.main(LbEmailMapper.java:47)
  • 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-25T12:32:05+00:00Added an answer on May 25, 2026 at 12:32 pm

    You should use

    psEmail = hrmsCon.prepareStatement(queryInsert );
    

    instead of

    psEmail = hrmsCon.prepareStatement( query );
    

    You should be careful when copy & paste code… 🙂

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

Sidebar

Related Questions

I wrote the following part which is a Java method with two STRING arguments
I wrote the following code: import java.lang.*; import DB.*; private Boolean validateInvoice(String i) {
I wrote following code...but i am getting Error like: Error 1 'LoginDLL.Class1.Login(string, string, string)':
I'm attempting to write a macro which will call java setter methods based on
Official problem: Write Java method to perform recursive descent parse of the following production:
The Netty library (written in Java) defines the following write method in the channel
I need to write java generic method that gets no parameter and returns a
i wrote following code to create a linkbutton programmatically, but its showing like lable
Wrote the following in PowersHell as a quick iTunes demonstration: $iTunes = New-Object -ComObject
I wrote the following javascript to put in my startup folder to work around

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.