hi hattusas,
Thanks for the reply... Iam not using servlets... I'll paste the code below and explain so that u can understand my problem.
I have a file called bkp.jsp
the path is
C:\Program Files\Apache Tomcat4.0\webapps\examples\jsp\select
The code is given below
<title>Select everything from a database</title>
</head>
<body>
</SCRIPT>
<jsp:useBean id="select" class="select.DataBaseSelect" scope="page">
<jsp:setProperty name="select" property="*" />
</jsp:useBean>
<% out.print(select.connect()); %>
<br>
<% out.print(select.select()); %>
<p>Format results
<br>
<%@ page import="java.util.Vector" %>
<% Vector aResult = select.getResult(); %>
<table>
<% for (int i=0; i < aResult.size(); i++) { %>
<tr>
<td>
<% out.print(aResult.elementAt(i)); %>
</td>
</tr>
<% } %>
</table>
</body>
</html>
I have a bean defined as follows. The path is
C:\Program Files\Apache Tomcat 4.0\webapps\examples\WEB-INF\classes\select
DSN name : Studentdb , table : stud , fields sno,sname
package select;
import java.sql.*;
import java.util.Vector;
/**
* DataBaseSelect.java
* Written by Morgan Catlin
* August 19, 1999
*
* Variables:
* Vector result = where I put the results of a select query
*
* Methods:
* Vector getResult() = returns result
* void setResult() = sets result
* String connect() = connects to a database
* String select() = selects information from a database
*/
public class DataBaseSelect {
private Vector result;
public DataBaseSelect() {
result = new Vector();
} // constructor DataBaseSelect
public String connect() {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"

.newInstance();
return "Driver Loaded!";
} catch (Exception E) {
return "Unable to load driver.";
}
}
public String select() {
try {
String url = "Jdbc

dbc:studentdb";
Connection C = DriverManager.getConnection(url,"admin","sa"

;
Statement Stmt = C.createStatement();
ResultSet myResult = Stmt.executeQuery("select sno,sname from stud"

;
while (myResult.next()) {
result.addElement(myResult.getString(1));
}
// Clean up
myResult.close();
Stmt.close();
C.close();
return "Connection Success!";
} catch (SQLException E) {
return "SQLException: " + E.getMessage();
}
}
/**
* Accessor for result
**/
public Vector getResult() {
return result;
}
/**
* Mutator for result
**/
public void setResult(Vector avector) {
result = avector;
}
} // class DataBaseSelect
The problem is
In the jsp file after the statement
<% out.print(aResult.elementAt(i)); %>
I want to add the elements in the array into a combo box
Iam not able to do so..
I tried to use the following code
<select name="id">
<table>
<% for (int i=0; i < aResult.size(); i++) { %>
<option value="<% =i %>" > <% =aResult.elementAt(i) %> </option>
<% } %>
It gives me an error.