This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Struts and the fly likes display items from DB, update and save ?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "display items from DB, update and save ??" Watch "display items from DB, update and save ??" New topic
Author

display items from DB, update and save ??

majid nakit
Ranch Hand

Joined: Jun 26, 2001
Posts: 164
Hi, I am looking for a database example for displaying items from a database update them and save thyem in a database.
I found this article :
http://faq.javaranch.com/java/IndexedProperties

please if you have a small example using a database OR how to make this faq example :
http://faq.javaranch.com/java/IndexedProperties

working with a database ?

thanks, your help is appreciated.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
The process of transferring data between a relational database and Java objects is the same regardless of what type of application you're writing. If you're not familiar with how JDBC works, I'd suggest you spend some time with some JDBC tutorials such as this one. Once you learn this process, you can simply plug the JDBC code into your Struts application. For example, if you wanted to make the example you've mentioned above use a real Database rather than just static variables, write some JDBC code and plug it into the IndexedBusinessLayer class and the rest of the example will work as-is.
[ October 02, 2007: Message edited by: Merrill Higginson ]

Merrill
Consultant, Sima Solutions
majid nakit
Ranch Hand

Joined: Jun 26, 2001
Posts: 164
Hi,
thank you for reply,

In IndexedBusinessLayer :
I know this method :

public static List getOrders()
{
will be a select from tables from database.
}

My problem is how to transform the update method :

public static void updateOrderQty(List orderList)
{
for(Iterator orderIter = orderList.iterator(); orderIter.hasNext()
{
OrderItem newItem = (OrderItem) orderIter.next();
String key = newItem.getProductId();
OrderItem orderItem = (OrderItem) orderMap.get(key);
if(orderItem != null)
{
orderItem.setQuantity(newItem.getQuantity());
}
}
}

to work with an update sql statement ?
I know SQL, I know how to write queries, please I will appreciate your help.
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
I know SQL, I know how to write queries

Then it does not seem like it would be too hard to translate the code into update queries. Are you just trying to get the example working with a database or are you trying to apply the concepts to your real application?

- Brent
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
It's one thing to be able to write SQL statements. It's another to be able to use them within the context of the JDBC API. If you don't already know how to use this API, you'll need to learn it before going any further. Here's a brief example:

[ October 02, 2007: Message edited by: Merrill Higginson ]
majid nakit
Ranch Hand

Joined: Jun 26, 2001
Posts: 164
Thank you very much, your help is appreciated.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: display items from DB, update and save ??
 
Similar Threads
Need Some Help Regarding the Validation -- Struts2
struts multiple values passing
struts2: how to create dynamic input field?
save indexed properties
Managing dynamic form elements in Struts