File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes basic simple jsp/bean/servlet cms mysql datasource Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "basic simple jsp/bean/servlet cms mysql datasource" Watch "basic simple jsp/bean/servlet cms mysql datasource" New topic
Author

basic simple jsp/bean/servlet cms mysql datasource

Sean McKernan
Greenhorn

Joined: Jan 10, 2005
Posts: 4
Hello!

I have built numerous webapps in php/mysql over the years that allow insert/modify/delete of db content...however, I am having some difficulty wrapping my brain around the java approach... I'm still not clear on what a "flow-chart" of the process would look like..(i.e. jsp form > servlet > bean > servlet > db > bean > servlet > jsp display ???)

Can anyone point me to a very simple example (employee data, cd collection, event calendar, etc...) that could help make this clear for me?

I had the j2ee structure thrust upon me due to my company purchasing websphere and all anyone could tell me was that I need to use the following code

****
InitialContext ctx = new InitialContext();
ds = (DataSource) ctx.lookup("java:comp/env/xxxxxx");
****

I guess I'll still need to figure out the necessary "package imports" and all the "exception handling", but I'm hoping to find something that will allow me to "drop in" this code and make minor edits to the db queries (which I DO understand...)

All replies will be greatly appreciated -- Thanks in advance!!!
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61451
    
  67

"Web Producer",

Glad that you're here with us on the good ol' JavaRanch and I reckon that you'll find this a helpful and useful site, but we do got us a few rules that y'all got to play by. One of these is that proper ID is required before you can belly on up to the bar. Please take a gander at the JavaRanch Naming Policy and adjust your display name to match it.

The particulars is that your display name must be a first and a last name separated by a space character, and must not be obviously pulling our legs!

Thank ya kindly!
bear
Forum Bartender


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61451
    
  67

For my apps, the usual flow of this kind of deal is usually along the lines of

1) JSP form submits to servlet
2) Servlet utilizes business layer to perform appropriate action
3) Servlet gathers info for display, data (usually beans) is placed in scoped variables on the request
4) Servlet forwards to JSP page

Sometimes there's a 3b where the processing servlet fowards to a "display prep" servlet if appropriate.
Sean McKernan
Greenhorn

Joined: Jan 10, 2005
Posts: 4
Sorry about the "alias" there...
I try to set up accounts so that when the time comes for me to leave the job, my successor can continue using the accounts...
Anyway...
I should be showing up as "Sean McKernan" now....Web Producer at Bryant University in Smithfield, RI...
Thanks for the chance to make it right....
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61451
    
  67

No prob! Thanks for responding so quickly.
Sean McKernan
Greenhorn

Joined: Jan 10, 2005
Posts: 4
You're quite welcome - thanks for providing this great space!!!

Anyway...

Back to the post...

Here is part of the question:

As for the code I mentioned earlier:

****
InitialContext ctx = new InitialContext();
ds = (DataSource) ctx.lookup("java:comp/env/xxxxxx");
Connection conn = ds.getConnection();
****

Does this constitute a straightforward one-to-one replacement for the following code?

****
Class.forName("com.imaginary.sql.msql.MsqlDriver");
String url = "jdbc:msql://www.myserver.com:1114/contact_mgr";
Connection conn = DriverManager.getConnection(url,"user1","password");
****
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30789
    
157

Sean,
Yes, it is a one to one correspondence (assuming you set up a datasource on the server.)


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Sean McKernan
Greenhorn

Joined: Jan 10, 2005
Posts: 4
Great!! Thanks!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: basic simple jsp/bean/servlet cms mysql datasource