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

The Archive Base Latest Questions

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

I was testing to transfer data of the result query to a String variable

  • 0

I was testing to transfer data of the result query to a String variable but when I did I received this bunch of errors, I don’t have any idea why did this occured, I tested my query in mysql and it worked, but how come in my code isn’t? here’s my test code

   package test;
import dao.FinanceDao;
import javax.swing.JTextArea;
import java.util.Scanner;
import java.util.List;
import javax.swing.JOptionPane;
import domainmodel.User;
import javax.sql.DataSource;
import org.springframework.jdbc.datasource.DriverManagerDataSource;

public class TestDrive {

    public static void main(String[] args){
        String employeeID = null;
        String password = null;
        JTextArea text = new JTextArea();
        FinanceDao finance = new FinanceDao();
        DataSource  dataSource = SourceObj.getSource();

        finance.setDataSource(dataSource);

        /*Scanner input = new Scanner(System.in);
        System.out.println("Enter your Choice for Employee ID");
        String empID = input.nextLine();
        System.out.println("Enter your choice for Password");
        String password = input.nextLine();
        finance.Add(empID,password);
        */
        String idNumber = JOptionPane.showInputDialog("Enter Employee ID to Search");

        List<User> test = finance.select(idNumber,"51010");
        for(User u: test){
        employeeID = u.getEmpID();
        password = u.getPassword();
        if(employeeID == null){
            text.setText("No Result");
        }else{
            text.setText("\tEmployeeID: "+employeeID+"\n\tPassword: "+password);
            }
        }

        UI U = new UI(text);
    }
}

and this one

package dao;

import javax.sql.DataSource;
import java.util.List;
import org.springframework.jdbc.core.JdbcTemplate;
import dao.mapper.UserRowMapper;
import domainmodel.User;

public class FinanceDao implements Manage {

    private DataSource ds;

    @Override
    public void setDataSource(DataSource ds) {
        this.ds = ds;

    }

    @Override
    public void Add(String empID, String password) {
        JdbcTemplate Add = new JdbcTemplate(ds);
        Add.update("INSERT INTO user (empID,password) VALUES(?,?)",
        new Object[] { empID, password });
    }

    @Override
    public void Delete(String empID , String password) {
        JdbcTemplate Delete = new JdbcTemplate(ds);
        Delete.update("Delete from User where emp_id = '?'",new Object[]{empID});
    }


    public List<User> select(String empID,String password) {
        JdbcTemplate select = new JdbcTemplate(ds);
        return select
                .query(
                        "SELECT EMPID ,PASSWORD from  USER where empID = '?' AND password = ?",
                        new Object[] {empID , password},
                        new UserRowMapper());
    }

}

the error

EDIT
and this is my error

Dec 2, 2011 6:02:29 AM org.springframework.jdbc.datasource.DriverManagerDataSource setDriverClassName
INFO: Loaded JDBC driver: com.mysql.jdbc.Driver
Dec 2, 2011 6:02:34 AM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [org/springframework/jdbc/support/sql-error-codes.xml]
Dec 2, 2011 6:02:34 AM org.springframework.jdbc.support.SQLErrorCodesFactory <init>
INFO: SQLErrorCodes loaded: [DB2, Derby, H2, HSQL, Informix, MS-SQL, MySQL, Oracle, PostgreSQL, Sybase]
Exception in thread "main" org.springframework.jdbc.UncategorizedSQLException: PreparedStatementCallback; uncategorized SQLException for SQL [SELECT EMPID ,PASSWORD from  USER where empID = '?' AND password = ?]; SQL state [S1009]; error code [0]; Parameter index out of range (2 > number of parameters, which is 1).; nested exception is java.sql.SQLException: Parameter index out of range (2 > number of parameters, which is 1).
    at org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.translate(SQLStateSQLExceptionTranslator.java:120)
    at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.translate(SQLErrorCodeSQLExceptionTranslator.java:276)
    at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:553)
    at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:587)
    at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:616)
    at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:624)
    at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:656)
    at dao.FinanceDao.select(FinanceDao.java:36)
    at test.TestDrive.main(TestDrive.java:32)
Caused by: java.sql.SQLException: Parameter index out of range (2 > number of parameters, which is 1).
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1073)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:987)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:982)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:927)
    at com.mysql.jdbc.PreparedStatement.checkBounds(PreparedStatement.java:3729)
    at com.mysql.jdbc.PreparedStatement.setInternal(PreparedStatement.java:3713)
    at com.mysql.jdbc.PreparedStatement.setString(PreparedStatement.java:4553)
    at org.springframework.jdbc.core.StatementCreatorUtils.setParameterValueInternal(StatementCreatorUtils.java:236)
    at org.springframework.jdbc.core.StatementCreatorUtils.setParameterValue(StatementCreatorUtils.java:94)
    at org.springframework.jdbc.core.ArgPreparedStatementSetter.setValues(ArgPreparedStatementSetter.java:51)
    at org.springframework.jdbc.core.JdbcTemplate$1.doInPreparedStatement(JdbcTemplate.java:592)
    at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:537)
    ... 6 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-27T04:12:14+00:00Added an answer on May 27, 2026 at 4:12 am

    In the search method where do you pass empID to the query?

        @Override
        public List<User> Search(String empID) {
            JdbcTemplate search = new JdbcTemplate(ds);
            return search.query("Select empID from user where empID = '?'",
            new UserRowMapper());
        }
    

    to me that looks rather suspicious. Shouldn’t it be something like

            return search.query("Select empID from user where empID = ?", new Object[]{empID}),new UserRowMapper());
    

    EDIT
    and also you need to remove the quotes around the question mark

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

Sidebar

Related Questions

This is an error that my friend is getting when testing my app, but
I have done a number of google searches on this topic, but haven't been
Does anyone have recommendations for testing data quality. Imagine you have staged data in
For testing purposes I have to generate a file of a certain size (to
Unit testing sounds great to me, but I'm not sure I should spend any
Unit testing with C/C++: What do you teach people who either did not do
I have a lot of data stored in my app on my provisioned device,
I had another question about this issue, but I didn't ask properly, so here
I have the following script (modified to remove any private information). -- This line
I have a new database, similar to the old one but with more columns

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.