Originally posted by Sarath Chandra:
Haijun,
A brief explanation on how you go ahead with JDeveloper :
1. Create a Project in JDeveloper Workspace (File->New Project).
2. Keep adding all your .java files to this project.
3. You can run any .java file, having a main() in it by right
clicking on that file and selecting "Run".
The most important thing would be the Project Properties window. Just double click on your project, Properties Window would get displayed.
In this project Properties Window, the tab "Run/Debug" is of significance in our scenario.
For the Topic "Debug Session Options", set the "Compile Project Before Running Or Debugging" to true by checking the check box.
For the Topic "Console I/O", select an appropriate thing from the radio group, either to send the output to the Message View, or to send run output to Console Window. [I'd prefer you choose the Console Window Option, every time when you run your program you'd be able to see a new MS-DOS window getting created with your program output.]
've a nice time with JDeveloper!!!
Originally posted by SoonAnn Lim:
Hi, as i can see, the solution you look for is not very obvious. There are several problems in your code. First, all sql codes must be in a try and catch block that throw SQLException. Second, you don't know the size of the array you are creating. If i were to solve this problem,
1. i will use a vector to store all the result from resultset. If your result set contains more than one column, then write a simple class to hold all the values from the results, then put the instances of the class into vector.
2. Then i can find the size of the vector using Vector.size, this let me create an array of String (your case) or array of other objects with correct size. After that you want to iterate through all the elements in your vector.
3. Use Enumeration to iterate through your vector. In Vector class, Vector.element() method return the enumeration of vector.
"Enumeration e = v.elements();".
4. Finally, a while loop can help you to iterate through all the element in the Enumeration. "while(e.hasMoreElements())", In this loop, you extract all objects from Enumeration and assign to your array(String or objects) with an explicit cast. The method is "Enumeration.nextElement()". For example,
a=0;
while (e.hasMoreElements()){
str[a++]=(String)e.nextElement();
}
Hope this will help.
Originally posted by Brian Nice:
in your bean, if you have the values stored in some sort of array or collection, either use a getter method to return your collection item and loop through the collection to form your drop down, or use an indexed getter to get particular items from your collection.
Example:
<% String [] AValues = bean.getValues();
if (Avalues != null) { %>
<select name="dropdown">
<% for (int i=0; i<Avalues.length; i++) {
String val = AValues[i]; %>
<option value="<%=val%>"><%=val%></option>
<% } %>
</select>
<% } %>
HTH
Brian
Originally posted by Vishakha Ahuja:
Since you have defined a while loop, why don't you use an index for array :
int a = 0;
while(rs.next()) {
stringArray[a] = rs.getString("x");
a++; }
Originally posted by Brian Nice:
When you come into the page, you could load some javascript arrays with all the selections for A, and another array to hold the selections for B. Then when the user chooses A or B, use javascript to change the values in the drop down menu.
Or you can refresh the page and send the page on the URL line, the selection of A or B. So when the user changes his selection, refresh the page with a parameter showing which was selected by appending it to the URL line, then get the selection from the request and based on that choose which drop down box you would like to display.
And yes, you can choose the drop down menu items from the database. I use a custom tag to do that, but you could also use a bean to read from the database and use JSP to go through th resultset and build the drop down box, or something similar.
HTH
Brian