aspose file tools
The moose likes JDBC and Relational Databases and the fly likes java.sql.SQLException: Column Index out of range, 2 > 1. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of The Software Craftsman this week in the Agile forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "java.sql.SQLException: Column Index out of range, 2 > 1." Watch "java.sql.SQLException: Column Index out of range, 2 > 1." New topic

java.sql.SQLException: Column Index out of range, 2 > 1.

priya pillai
Ranch Hand

Joined: Sep 12, 2007
Posts: 57
Dear Friends,

I am doing a small program with jsp and javaBean.

My table details are


color_code varchar(10) not null, PK
color_desc varchar(100) not null,

My JSP program is

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">

<%@page import="bean.vsms.colorBean"%>
<%@page import="java.util.Vector" %>
<%@page import = "java.util.Iterator" %>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
colorBean cb = new colorBean();
Vector v = new Vector();
Iterator itr = v.iterator();
while (itr.hasNext())
System.out.println("elements are" +;
}catch(Exception e)
System.out.println("exception occured prog" + e);



My Bean Program is

package bean.vsms;

//import java.sql.DriverManager;
import javax.sql.DataSource; //This will be obtained using a JNDI Name
import javax.naming.Context; //imports for using the InitialContext of the Weblogic JNDI Tree and lookup for JNDI Names
import javax.naming.InitialContext;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Collection;
import java.util.ArrayList;
import java.util.Vector;

*A JavaBean is a re-usable component (class) that can be serialized. It basically refers to an Entity. Here Entity is Department

public class colorBean implements Serializable{

//instance variables

private String color_code;
private String color_desc;

public colorBean(String color_code, String color_desc) {
this.color_code = color_code;
this.color_desc = color_desc;
public colorBean() {

this.color_code = "";
this.color_desc = "";
public String getColor_code() {
return color_code;
public void setColor_code(String color_code) {
this.color_code = color_code;
public String getColor_desc() {
return color_desc;
public void setColor_desc(String color_desc) {
this.color_desc = color_desc;

String JNDIName = "vsmsDS"; //this is the DataSource JNDI Name configured on the Weblogic Server
Connection con = null;
Statement st = null;
ResultSet rs = null;

private void connect(){
Context ctx = new InitialContext(); //obtains the InitialContext of the JNDI Tree
DataSource ds = (DataSource) ctx.lookup("vsmsDS"); //lookup and return an Object from the JNDI Tree
con = ds.getConnection(); //this will create the connection object from the factory i.e. DataSource
catch(Exception e){
public Vector findAllColor(){
Vector v = new Vector();
st = con.createStatement();
rs = st.executeQuery("SELECT color_desc FROM color");
boolean found = false;
found = true;
if(!found) System.out.println("no records found found");
catch(Exception e){
System.out.println("exeption in the color beanprog" + e);
return v;


exeption in the progjava.sql.SQLException: Column Index out of range, 2 > 1.

This error is from the bean class

pls anybody help me to sort out of this

thanks in advance
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 31668

Which line of code is throwing that exception specifically?

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
priya pillai
Ranch Hand

Joined: Sep 12, 2007
Posts: 57
I got the solution...i got exception in bean class...anyway thank you for reply
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: java.sql.SQLException: Column Index out of range, 2 > 1.