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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:14:03+00:00 2026-06-12T21:14:03+00:00

Please have a look at the following code DatabaseHandler.java public List getDetails(String name) {

  • 0

Please have a look at the following code

DatabaseHandler.java

public List getDetails(String name)
    {
        List details = new ArrayList();

        name = name.replaceAll("\\s+", "").toUpperCase();
        try
        {
            createConnection();

            PreparedStatement ps = con.prepareStatement("select * from PhoneData where upper(rtrim(NULLIF(names,''))) || upper(rtrim(NULLIF(middleName,''))) ||  upper(rtrim(NULLIF(lastName,'')))=?");
            ps.setString(1, name);

            ResultSet rs = ps.executeQuery();

          // System.out.println("First Mobile Number: "+rs.getInt(3));
            while(rs.next())
            {
                details.add(rs.getInt(1));
                details.add(rs.getString(2));
                details.add(rs.getString(3));
                details.add(rs.getString(4));
                details.add(rs.getString(5));
                details.add(rs.getString(6));
                details.add(rs.getString(7));
                details.add(rs.getString(8));
                details.add(rs.getString(9));
                details.add(rs.getString(10));
                details.add(rs.getString(11));
                details.add(rs.getString(12));
                details.add(rs.getString(13));
                details.add(rs.getString(14));
            }

            for(int i=0;i<details.size();i++)
            {
                System.out.println(details.get(i));
            }
            System.out.println("------------Database handler Done------------");
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
        finally
        {
            closeConnection();
        }

        return details;
    }

Above code is called by the following code, via an interface

UpdateDeleteForm.java

private class DetailsLoader implements ItemListener
    {
        public void itemStateChanged(ItemEvent ie)
        {
            if(ie.getStateChange()==ItemEvent.SELECTED)
            {
                List details = new ArrayList();


                if(nameTxtCombo.getSelectedItem().toString() != "Select a Name")
                {
                details = dateBaseConnector.getDetails(nameTxtCombo.getSelectedItem().toString());

                idTxt.setText("");
                firstNameTxt.setText("");
                lastNameTxt.setText("");
                mobileNumber1Txt.setText("");
                mobileNumber2Txt.setText("");
                landNumber1Txt.setText("");
                landNumber2Txt.setText("");
                streetAddressTxt.setText("");
                cityTxt.setText("");
                countryTxt.setText("");
                middleNameTxt.setText("");
                emailTxt.setText("");
                nickNameTxt.setText("");






                String mobileNumber1 = (String)details.get(2)+" ";
                String mobileNumber2 = (String)details.get(3)+" ";
                String landNumber1 = (String)details.get(4)+" ";
                String landNumber2 = (String)details.get(5)+" ";
                String address = (String)details.get(6)+" ";

                idTxt.setText(String.valueOf(details.get(0)));
                firstNameTxt.setText((String)details.get(1));                    
                mobileNumber1Txt.setText(mobileNumber1.trim());
                mobileNumber2Txt.setText(mobileNumber2.trim());
                landNumber1Txt.setText(landNumber1.trim());
                landNumber2Txt.setText(landNumber2.trim());
                streetAddressTxt.setText(address.trim());
                //categoryCombo.setSelectedItem((String)details.get(7));
                nickNameTxt.setText((String)details.get(8));
                emailTxt.setText((String)details.get(9));
                middleNameTxt.setText((String)details.get(10));
                lastNameTxt.setText((String)details.get(11));
                cityTxt.setText((String)details.get(12));
                countryTxt.setText((String)details.get(13));

                System.out.println((String)details.get(2));
                System.out.println((String)details.get(3));
                System.out.println((String)details.get(4));
                System.out.println((String)details.get(5));
                System.out.println(address.trim());
                System.out.println((String)details.get(7));
                System.out.println((String)details.get(8));
                System.out.println((String)details.get(9));
                System.out.println();
                System.out.println();
                System.out.println("---------------New Line---------------------");
                }

            }
        }
    }

This code works 100% fine when I am using MS SQLServer. But, now I am moving it to Apache Derby – Embedded version.

If any of the items returned by the getDetails() method is null, I am getting the following error

Exception in thread "AWT-EventQueue-0" java.lang.IndexOutOfBoundsException: Index: 2, Size: 0
    at java.util.ArrayList.rangeCheck(ArrayList.java:604)
    at java.util.ArrayList.get(ArrayList.java:382)
    at normal.UpdateDeleteForm$DetailsLoader.itemStateChanged(UpdateDeleteForm.java:438)
    at javax.swing.JComboBox.fireItemStateChanged(JComboBox.java:1225)
    at javax.swing.JComboBox.selectedItemChanged(JComboBox.java:1282)
    at javax.swing.JComboBox.contentsChanged(JComboBox.java:1329)
    at javax.swing.AbstractListModel.fireContentsChanged(AbstractListModel.java:118)
    at javax.swing.DefaultComboBoxModel.setSelectedItem(DefaultComboBoxModel.java:94)
    at javax.swing.JComboBox.setSelectedItem(JComboBox.java:578)
    at javax.swing.JComboBox.setSelectedIndex(JComboBox.java:624)
    at javax.swing.plaf.basic.BasicComboPopup$Handler.mouseReleased(BasicComboPopup.java:835)
    at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:290)
    at java.awt.Component.processMouseEvent(Component.java:6504)
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
    at javax.swing.plaf.basic.BasicComboPopup$1.processMouseEvent(BasicComboPopup.java:499)
    at java.awt.Component.processEvent(Component.java:6269)
    at java.awt.Container.processEvent(Container.java:2229)
    at java.awt.Component.dispatchEventImpl(Component.java:4860)
    at java.awt.Container.dispatchEventImpl(Container.java:2287)
    at java.awt.Component.dispatchEvent(Component.java:4686)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
    at java.awt.Container.dispatchEventImpl(Container.java:2273)
    at java.awt.Window.dispatchEventImpl(Window.java:2713)
    at java.awt.Component.dispatchEvent(Component.java:4686)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:707)
    at java.awt.EventQueue.access$000(EventQueue.java:101)
    at java.awt.EventQueue$3.run(EventQueue.java:666)
    at java.awt.EventQueue$3.run(EventQueue.java:664)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
    at java.awt.EventQueue$4.run(EventQueue.java:680)
    at java.awt.EventQueue$4.run(EventQueue.java:678)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:677)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:211)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:90)

If non is null, then no issue at all. I can remember I had the same issue in MS SQL Server, and I managed to overcome it with ‘isnull’. I have done the same here, but seems like apache version of isnull (nullif) is not working, because if it at least returned a blank space, I am not having this issue!! Please 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-12T21:14:04+00:00Added an answer on June 12, 2026 at 9:14 pm

    COALESCE is much more to use in your PreparedStatement

    PreparedStatement ps = con.prepareStatement("
                                    select * 
                                    from PhoneData 
                                    where upper(rtrim(COALESCE(names,''))) || 
                                          upper(rtrim(COALESCE(middleName,''))) ||  
                                          upper(rtrim(COALESCE(lastName,''))) = ?");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

please have a look at the following code import java.util.ArrayList; import java.util.List; public class
Please have a look at the following code package Euler; import java.util.ArrayList; import java.util.List;
Please have a look at following code : import java.util.ArrayList; import java.util.List; class Main{
Please have a look at the following code public List searchData(String query) { List
Please have a look at the following code DataBaseConnector.java import java.sql.*; import javax.swing.*; public
Please have a look the following code import javax.swing.*; import java.awt.event.*; import java.awt.*; public
am new here. i have a slight problem; PLease look at the following code
Please have look on the following code: $_SESSION[process_y] = new Process(); $process_y = $_SESSION[process_y];
Please have a look at the following code import java.awt.Color; import java.awt.Dimension; import java.awt.FlowLayout;
Please have a look at the following code. import java.awt.FlowLayout; import java.awt.GridLayout; import javax.swing.*;

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.