it is strange that my code was working before I modified some variable name/ type. i didn't make any major changes except for changing from double to int, and from double to String. the change was involved a bit sql code change as well though.


i got (does anyone have any clue what possibly went wrong?)

Column Index out of range, 30 > 12. 
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:910)
	at com.mysql.jdbc.ResultSet.checkColumnBounds(ResultSet.java:690)
	at com.mysql.jdbc.ResultSet.getStringInternal(ResultSet.java:5625)
	at com.mysql.jdbc.ResultSet.getString(ResultSet.java:5544)
	at DataHolder.search(DataHolder.java:196)
	at Search.actionPerformed(Search.java:74)
	at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
	at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
	at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
	at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
	at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
	at java.awt.Component.processMouseEvent(Unknown Source)
	at javax.swing.JComponent.processMouseEvent(Unknown Source)
	at java.awt.Component.processEvent(Unknown Source)
	at java.awt.Container.processEvent(Unknown Source)
	at java.awt.Component.dispatchEventImpl(Unknown Source)
	at java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
	at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
	at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
	at java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.awt.Window.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.EventQueue.dispatchEvent(Unknown Source)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.run(Unknown Source)
java.sql.SQLException: Column Index out of range, 30 > 12. 
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:910)
	at com.mysql.jdbc.ResultSet.checkColumnBounds(ResultSet.java:690)
	at com.mysql.jdbc.ResultSet.getStringInternal(ResultSet.java:5625)
	at com.mysql.jdbc.ResultSet.getString(ResultSet.java:5544)
	at DataHolder.search(DataHolder.java:196)
	at Search.actionPerformed(Search.java:74)
	at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
	at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
	at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
	at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
	at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
	at java.awt.Component.processMouseEvent(Unknown Source)
	at javax.swing.JComponent.processMouseEvent(Unknown Source)
	at java.awt.Component.processEvent(Unknown Source)
	at java.awt.Container.processEvent(Unknown Source)
	at java.awt.Component.dispatchEventImpl(Unknown Source)
	at java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
	at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
	at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
	at java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.awt.Window.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.EventQueue.dispatchEvent(Unknown Source)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.run(Unknown Source)

this is the class if needed ....

//import java.text.MessageFormat;
import java.util.*;
import javax.swing.*;

//import java.awt.*;
import java.awt.event.*;

public class Search implements ActionListener
{
	private JFrame frame;
	private RecordCP cp;
	private JButton searchPrevious, searchNext, payRollButton, dummyButton;
	private DataHolder dh = new DataHolder(true);
	private LinkedList<Employee> employeeList = new LinkedList<Employee>();
	int id, age, salary;
	String fn, ln, ph, add, city, st, zip, sex, position;
	//double hourly, hours;
	private int count=-1, countTotal=0;
	
	public Search(JFrame f)
	{
		frame = f;
		cp = new RecordCP(f);  //this is a JPanel with the form
		
		searchPrevious= new JButton("Search (Back)");
		searchPrevious.addActionListener(this);
		
		searchNext = new JButton("Search (Next)");
		searchNext.addActionListener(this);
		
		payRollButton = new JButton("Show Payroll Info");
		payRollButton.addActionListener(this);
		
		dummyButton = new JButton("");
		
		cp.add(searchNext);
		cp.add(searchPrevious);
		cp.add(payRollButton);
		cp.add(dummyButton);
		
	}
	
	
	public void actionPerformed(ActionEvent e)
	{
		frame.getContentPane().removeAll();
		cp.setBounds(400, 400, 400, 200);
		cp.setVisible(true);
		frame.add(cp);
		frame.validate();
	    frame.setVisible(true);
	    frame.repaint();
		
	    cp.getIDF().setEnabled(false);
	    cp.getPHF().setEnabled(false);
	    cp.getAddF().setEnabled(false);
	    cp.getCityF().setEnabled(false);
	    cp.getSTF().setEnabled(false);
	    cp.getZipF().setEnabled(false);
	    cp.getAgeF().setEnabled(false);
	    cp.getSexF().setEnabled(false);
	    cp.getSalaryF().setEnabled(false);
	    cp.getPositionF().setEnabled(false);
	    
		 /////////////////// query pool ////////////////////////
	    String queryFNAndLN = "SELECT * FROM employees WHERE firstName in(?) AND lastName in(?)";
	    
	    String queryLNLike = "SELECT * FROM employees WHERE firstName LIKE in(?)"+
        "'" +ln+ "%" + "'"; 
        //" AND lastName LIKE"+" '" +"ln"+ "%"+ "'";
	    /////////////////// end query pool ////////////////////
	    
	    
	    employeeList = dh.search(cp.getFields().get(1), cp.getFields().get(2), queryFNAndLN);
	    //employeeList = dh.search(fnField.getText(), lnField.getText(), queryLNLike);
	    countTotal= employeeList.size();
		
		if(e.getSource() == searchNext)
		{
			if(checker() == true)
			{
				count++;
				if(count == countTotal)
				{
					JOptionPane.showMessageDialog(null, "No more record");
					count--;
				}
				else
				{search(count);}
			}
		}
		
		else if(e.getSource() == searchPrevious)
		{
			if(checker() == true)
			{
				count--;
				if(count < 0)
				{
					JOptionPane.showMessageDialog(null, "No more record");
					count++;
				}
				else
				{search(count);}
			}
		}
		
		else if(e.getSource() == payRollButton)
		{
			if(cp.getIDF().getText().equals(""))
			{
				JOptionPane.showMessageDialog(null, "Please search for a record first.");
			}
			
			else
			{
				cp.getFields();
				Employee em = new Employee(new Integer(cp.getFields().get(0)), cp.getFields().get(1), cp.getFields().get(2), cp.getFields().get(3), 
				 	                  cp.getFields().get(4), cp.getFields().get(5), cp.getFields().get(6), cp.getFields().get(7),  
				 	                 new Integer(cp.getFields().get(8)), cp.getFields().get(9), new Integer(cp.getFields().get(10)), cp.getFields().get(11)); 	
			
				JOptionPane.showMessageDialog(null, em.toString());
			}
		}
		
	}// end ActionPerformed
	
	
	public void search(int count)
	{
		
		cp.getIDF().setText(Integer.toString(employeeList.get(count).getID()));
		cp.getFNF().setText(employeeList.get(count).getFirstName());
		cp.getLNF().setText(employeeList.get(count).getLastName());
		cp.getPHF().setText(employeeList.get(count).getPhone());
		cp.getAddF().setText(employeeList.get(count).getAddress());
		cp.getCityF().setText(employeeList.get(count).getCity());
		cp.getSTF().setText(employeeList.get(count).getState());
		cp.getZipF().setText(employeeList.get(count).getZipCode());
		cp.getAgeF().setText(Integer.toString(employeeList.get(count).getAge()));
		cp.getSexF().setText(employeeList.get(count).getSex());
		cp.getSalaryF().setText(Integer.toString(employeeList.get(count).getSalary()));
		cp.getPositionF().setText(employeeList.get(count).getPosition());
		
	}
	
	public boolean checker()
	{
		boolean good = true;
		
		if(cp.getFNF().getText().equals("") || cp.getLNF().getText().equals(""))
		{
			JOptionPane.showMessageDialog(null, "You must enter first and last name to search. "+
					                            "leaving first and last name blank will make the searcher to seach for record with no names.");
			good=false;
		}
		else
		{
			good = true;
		}
		
		return good;
	}

	
	
}// end class
String queryLNLike = "SELECT * FROM employees WHERE firstName LIKE in(?)"+
"'" +ln+ "%" + "'";

Like In?

I don't think that could ever work.

huh, good catch. however, i never really used that variable... i will fix that though. thanks.

however, the major problem is still being the sql exception.

That "class" however, is not doing any SQL. You need to provide the DataHolder class. Also, currently you are doing your work on the event thread which is more than just wrong. You need to learn about MVC and use it. At the very least, you need to completely separate your DB and GUI code and do the actual DB work in a separate thread that then triggers an update of the GUI.

thanks very much for your opinion. i am actually working on improving the code of this program. I wrote this program last year. anyway, i just looked over the DataHolder class and found a small mistake causing the sql exception. Thanks very much.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.