This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
hi, i creating a form which can get data from DB, and this form mostly have textfield and also how to make it savable at the same time ? i actually don't know how to display data into textfield..thank you
since you're posting this topic on JSP category of the forum, i assume you are trying to do what you were asking by JSP. well, first of all you must build a connection to your DBMS, which you haven't mention yet in your posting. then create a database query to choose the data you want, since you are trying to retrieve data from database you should use a SELECT query to a table or a view. the query result, in JSP, can be stored in a java class ResultSet, from that class you can put the retrieved data into a textfield, even into a combo box, or simply display it on your web site's screen. So i need to know what kind of DBMS do you use? SQL Server, MySQL, PostgreSQL, or else? by then we can start the explanation all over again, OK? regards
Joined: Jan 08, 2004
hi, evan , thanks for reply , i understand the basic concept of jsp which get and set the data from or to DB, the thing i confuse is , let say i have many fields something as below
as show above, i use javabeans to retrieve data and pass it into textfield, my problem is if i want to make the form which is editable and then allow user to save the data into DB after click the modify button , how to i do that ?
Introducing PSEUDO code to give you insight This is not real code but it shows main idea
SELECT Name, Id FROM Users WHERE Id=SomeId ResultSet rs = use jdbc ^^^^ MyUserBean mub = MyUserBean(); mub.setId(rs.getInt("Id")); mub.setName(rs.getString("Name")); %> <form action="/editUser.jsp" method="post"> <input type="text" name="name" value="<%=mub.getName()%>"> <input type="text" name="id" value="<%=mub.getId()%>"> <input type="submit"> </form>
----->> SUBMIT -->>> <% String id = request.getParameter("id"); String name = request.getParameter("name");
JDBC... "UPDATE Users SET id= " + id + ", name='" + name + "' WHERE id = " + id; Execute it %>
Joined: Jan 08, 2004
would it be a problem since i already put the value into textfield , and then modify and save it again ? as we see
would it save back the qb.getCustsn() value rather than modified value in textfield?
Joined: Feb 16, 2005
the request.getParameter will technically read the last value of the parameter, in this case, the username textfield. so when you update the username field in the db, it will automatically updaetd, and when the second time visit that page the value will have changed remember that request.getParameter is triggered when you submitted a form, so the changes will occur after you press the ,let's say, 'Save' button try it n have fun!