Hi I am trying get user info from the database into the textbox when i select Usename Which is stored in the drop down. so could any help how to get all usernames into dropdown and when i select any usenames i should get all details into the text box.........please elp me
what is your question? how to get the usernames and put them in the drop down box, or how to get the userinfo based on these users?
write a class to connect to the db, write the code that reads the date in the db and use it.
first of all, this forum is not intended to deliver instant j2ee sollutions, and even if it was, we don't know what you are doing, whether you are using a framework, ...
make a start and come back with questions about your code, not with the classical no-no "plz write mah codez" or something of that sort
stultuske
Posting Sensei
3,137 posts since Jan 2007
Reputation Points: 1,114
Solved Threads: 433
This all depends entirely on where your usernames are stored. In a database? A file? Hard-coded?(better not be)
Open the Java API docs and review the contructors for JComboBox (assuming you plan to use the Swing framework) and that'll give you some ideas on how to add usernames to the drop-down list.
http://java.sun.com/docs/books/tutorial/uiswing/components/combobox.html
Add an ActionListener to the combo box to listen for when a username is selected from the list. Then simply connect to your database and pull the information you need. JTextField.setText() will set the text of the text box.
Phaelax
Practically a Posting Shark
858 posts since Mar 2004
Reputation Points: 92
Solved Threads: 51
Next time be more clear about what is your problem. From what I understood you don't know how to get and use the username from the comboBox?
If yes assume that you have a String username variable. For getting the value from a comboBox that has String elements do this:
String username = comboBox.getSelectedItem().toString() ;
Then create in a seperate class a method that take as argument that username and calls your query
class DBManager {
public void/*or whatever you want to return*/ method(String username) throws SQLException {
// code here
}
And call it with argument what you get from the comboBox.
String username = comboBox.getSelectedItem().toString() ;
DBManager dbM = new DBManager();
try {
dbM.method(username);
} catch (Exception e) {
}
javaAddict
Nearly a Senior Poster
3,329 posts since Dec 2007
Reputation Points: 1,014
Solved Threads: 448
Is this part of an application or it should be used as part of web service?
peter_budo
Code tags enforcer
15,436 posts since Dec 2004
Reputation Points: 2,806
Solved Threads: 902
thats ok after getting the data from the database i need to display the values in text fields. I mean when i select the username in drop down all the information of that perticular user should be displayed in the text.......which is nothing but getting user info...so wat i have to do?
What is your problem? Getting the data from DB or displaying them? Because displaying them is easy. Just call the setText() method of the JTextFields you have. It you want JTextArea call the append() method.
If it is JSP then use: <%= variable%> to display the value of variable in HTML
javaAddict
Nearly a Senior Poster
3,329 posts since Dec 2007
Reputation Points: 1,014
Solved Threads: 448
ya its a part of application. i need edit user information and store new values into same location.
<%!ArrayList usernameslist; %>
<%
InsertRegister insrt=new InsertRegister();
try{
usernameslist=insrt.editUserInfo();
}
catch(SQLException sqe)
{
out.print(sqe.toString());
}
%>
<select type="text" name="select" class="spacer" id="select" onchange="fnChangeHandler_A(this, event); submitAction('EditUserInfo');">
<option>Select UserName</option>
<% Iterator itres=usernameslist.iterator();
while(itres.hasNext())
{ String value=(String)itres.next();
out.println("<option value='"+value+"' onclick='submitAction('EditUserInfo')'>"+value+"</option>");
}%>
</select>
</label></td>
</tr>
This web service!
Request made to move this to JSP section...
Database connectivity from JSP is bad thing thing to do. Use servlets!
Secondly please start using[code]YOUR CODE HERE[/code]
peter_budo
Code tags enforcer
15,436 posts since Dec 2004
Reputation Points: 2,806
Solved Threads: 902