Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

java.util.NoSuchElementException while using StringTokenizer in jsp 1

Status
Not open for further replies.

nubees

Programmer
Aug 6, 2003
39
0
0
US

Vector Sedf1_vec = new Vector ((Vector) Simple_SearchBean.getSedf1_vec());
ListIterator iter_eres = Sedf1_vec.listIterator();

<table border ="1" bgcolor="#FFFCC">
<tr>
<th>Vendor</th> <th>Model</th> <th>Logical Name</th> <th>Facility</th> <th>Grid-999</th> <th>Grid-Aaa</th> <th>Cabinet</th>
</tr>

<tr>
<% while (iter_eres.hasNext()) {%>
<% String value = (String)iter_eres.next();%>
<%StringTokenizer stoken = new StringTokenizer(value," ");

for(int i=0;i<7;i++) {
String firsttok = stoken.nextToken();%>
<td> <%=firsttok%> </td> </b>
<%}%>
</tr>

<% } %>

</table>

************BEAN*************
while(rs.next()) {
e1 = rs.getString("Vendor");
e2 = rs.getString("Model");
e3 = rs.getString("Logical name");
e4 = rs.getString("Facility");
e5 = rs.getString("Grid-999");
e6 = rs.getString("Grid-Aaa");
e7 = rs.getString("Cabinet");
Sedf1_vec.addElement( e1+ "\n" +e2+ "\n" + e3+ "\n" + e4+ "\n" +e5+ "\n" +e6+ "\n" +e7+ "\n" );
}

Its working good if I donot use the String Tokenizer.

Thanks,
nubee
 
I don't know where are all that variables coming from, but what is happening is that the variable value that you're tokenizing does not contain 7 tokens are you're requesting in your for statemen.

I'd replace that for with a

Code:
while (stoken.hasMoreTokens())

Cheers,

Dian
 
Thanks Dian for the reply,sorry for getting back late on this.
I tried using

Code:
while (stoken.hasMoreTokens())

but I am getting an error Method hasNext is not found in class java.util.StringTokenizer

Code:
THIS IS THE BEAN CODE I AM USING IN THE JSP
package PlanningBeans;
import java.beans.*;
import javax.servlet.http.*;
import javax.servlet.*;
import java.sql.*;
import java.io.*;
import java.util.*;
import java.text.NumberFormat;

public class Simple_SearchBean {
HttpServletRequest request;
		private Connection conn;
		Statement st;
		ResultSet rs;
		String Edf_rad;
		String e1,e2,e3,e4,e5,e6,e7;
		Vector Sedf1_vec = new Vector();

		int i = 0;
		ResultSetMetaData rsmd;
		int numColumns=0;
		String sero,one1,two2,three3;
private String dbDriver="sun.jdbc.odbc.JdbcOdbcDriver";

		public Simple_SearchBean() throws ClassNotFoundException, SQLException{
		 	Class.forName(dbDriver);
		 	conn=DriverManager.getConnection("jdbc:odbc:planningdb","", "");

		}

public void processRequest5(HttpServletRequest request,HttpSession session)throws ServletException,IOException {
	System.out.println("Entered in processrequest5 table query method begining of simple search bean for edf");
	try {
	st=conn.createStatement();
	rs=st.executeQuery("Select Vendor,Model,[Logical Name],Facility,[Grid-999],[Grid-Aaa],Cabinet from [Base Inventory Table] where trim(Group) = 'EDF'");
	while(rs.next()) {
	e1 = rs.getString("Vendor");
	  e2 = rs.getString("Model");
	  e3 = rs.getString("Logical name");
	  e4 = rs.getString("Facility");
	  e5 = rs.getString("Grid-999");
           e6 = rs.getString("Grid-Aaa");
	  e7 = rs.getString("Cabinet");
	Sedf1_vec.addElement( e1+ "\n" +e2+ "\n" + e3+ "\n" + e4+ "\n" +e5+ "\n" +e6+ "\n" +e7+ "\n"  );
	}
}catch(SQLException exe){}
}
 
I forgot to add this code part previously

Code:
 public Object getSedf1_vec() {
								return this.Sedf1_vec;
				}
 
oh my bad,
I used hasNext instead of hasMoreTokens you are right, I could get that to work.

Thanks a lot Dian.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top