• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Friends,

I am doing a small program with jsp and javaBean.

My table details are

color

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"
pageEncoding="ISO-8859-1"
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

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

}

%>
</body>
</html>

My Bean Program is

package bean.vsms;

import java.io.Serializable;
//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) {
super();
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(){
try{
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){
e.printStackTrace();
}
}
public Vector findAllColor(){
Vector v = new Vector();
try{
connect();
st = con.createStatement();
rs = st.executeQuery("SELECT color_desc FROM color");
boolean found = false;
while(rs.next()){
found = true;
v.add(rs.getString("color_desc"));
}
rs.close();
st.close();
con.close();
if(!found) System.out.println("no records found found");
}
catch(Exception e){
System.out.println("exeption in the color beanprog" + e);
}
return v;
}
}


I AM GETTING THE ERROR OF

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
priya
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Priya,
Which line of code is throwing that exception specifically?
 
priya pillai
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
reply
    Bookmark Topic Watch Topic
  • New Topic