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

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

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.

Ok thanks for your help, Actually i need to edit the user information which is stored in the mysql database, for that i need to fetch the data from database for perticular user. I have written java class in that I am storing all the usernames in an Array list. I need to display these ArrayList usernames in drop down box. I dont how to do that pls help me

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.

Ok thanks for your help, Actually i need to edit the user information which is stored in the mysql database, for that i need to fetch the data from database for perticular user. I have written java class in that I am storing all the usernames in an Array list. I need to display these ArrayList usernames in drop down box. I dont how to do that pls help me

Ok thanks for your help, Actually i need to edit the user information which is stored in the mysql database, for that i need to fetch the data from database for perticular user. I have written java class in that I am storing all the usernames in an Array list. I need to display these ArrayList usernames in drop down box. I dont how to do that pls help me

Hello,

There are two ways to add usernames from ArrayList to ComboBox (that i have in mind now).

One is using forloop, Get each username from ArrayList and add it to ComboBox.

and second one is, Get Array object from ArrayList using toArray() method.

JComboBox comboObj = new JComboBox(Object []usernames);

and use this constructor. This will automatically add all elements of Array into ComboBox.

Regards,

I need to fetch the data from database by using usernames which is in drop down, for this i need to write a query such that for where condition in query i need give the username,....then that query will execute and it vl return some user data.Now the problem is whenthe user select username which is in drop down that username should be the condition in query i dont know how to use this username in my query.......some one told me to use session....is it ok shell i use session...please help me its very urgent

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) {

}

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?

Is this part of an application or it should be used as part of web service?

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

Is this part of an application or it should be used as part of web service?

ya its a part of application. i need edit user information and store new values into same location.

ok i will explain clearly and i will tell my over all work.

in our project we have admin module. ok when admin login into his account if he wants to change user information which is nothing but usermanagement section(usermanagement.jsp). when admin comes this page there is a drop down. In that drop down all the username should be fetched from the database so that when admin selects perticular username then in remaining fields such as designation, role, email should come from database for that perticular user.

now am getting all the user names in drop down which is as shown below

<%!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>

now the problem is i need to get the information into the text box by using this username list.

i think now you got my problem...

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]

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.