my dog learned polymorphism*
The moose likes JSP and the fly likes Insert/Update recordset Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Insert/Update recordset" Watch "Insert/Update recordset" New topic
Author

Insert/Update recordset

Bashar Ayyash
Ranch Hand

Joined: Jun 24, 2004
Posts: 44
Hi Guys,

How can I make a JSP page view or update the recordset if there is any in the DB, or allow the user to insert a new recordset?

thanx,
Bimal Patel
Ranch Hand

Joined: Aug 29, 2003
Posts: 130
Hi,

Yes you can obviously do. You can do some JDBC coding in JSP itself by scriptlets or adopt a design pattern like MVC and put the JDBC code in your model part.
[ January 20, 2006: Message edited by: Bimal Patel ]

Work Hard, Expect The Worst...<br /> <br />Bimal R. Patel<br />(SCJP 1.2, SCWCD 1.4)
Bashar Ayyash
Ranch Hand

Joined: Jun 24, 2004
Posts: 44
can you help me and give me some code or links that explains inserting JDBC code in JSP, to make the page update/insert recordset?

Thanx,
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60765
    
  65

Putting code, especially database code, on a JSP is not considered a very good practice. It's a much better idea to factor such code into model classes as Bimal indicated.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bimal Patel
Ranch Hand

Joined: Aug 29, 2003
Posts: 130
Hi,

That is the same way as you access a DB from JDBC from a stand alone class. 1. Load the drivers, 2. Aquire a connection object, 3. Get a simple/prepared statement object and 4. execute your sql update/insert by executeUpdate() method. But you should do this in the model layer rather then the view/presentation one.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by Bashar Ayyash:
can you help me and give me some code or links that explains inserting JDBC code in JSP, to make the page update/insert recordset?

Thanx,


I would start out with a few Google searches on JDBC Tutorial.
There are quite a few out there so you should be able to find one that suits your taste pretty easily.
fficial" target="_blank" rel="nofollow">http://www.google.com/search?q=JDBC+TUTORIAL&start=0&start=0&ie=utf-8&oe=utf-8&client=firefox-a&rls=org.mozilla:en-USfficial

There is also a JDBC forum on this list.

As always, I recommend getting your database calls working in a simple, standalone Java class from the command line. Once you've done that, you can easily call that class from your JSP.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Insert/Update recordset
 
Similar Threads
About Cursor
update while doing save in hibernate
Jump to a specific record of a Resultset
Problem withUpdatable Resultset
Updating members in physical file - AS/400.