| Author |
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 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
|
 |
Jeanne Boyarsky
internet detective
Marshal
Joined: May 26, 2003
Posts: 26499
|
|
Priya, Which line of code is throwing that exception specifically?
|
[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
|
 |
 |
|
|
subject: java.sql.SQLException: Column Index out of range, 2 > 1.
|
|
|