Design idea?

Reply

Join Date: Jun 2007
Posts: 11
Reputation: sundar divas is an unknown quantity at this point 
Solved Threads: 0
sundar divas sundar divas is offline Offline
Newbie Poster

Design idea?

 
0
  #1
Nov 15th, 2008
Q: Create a JSP based page wherein by clicking the add button the user details should be added to the database and clicking the delete button should delete the particular user details from the database. I am new to JSP so dont have much idea how to proceed? Do we need to use JDBC or we can create & manipulate a database using JSP?

Please help me to start....
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 16
Reputation: vee_liang is an unknown quantity at this point 
Solved Threads: 1
vee_liang vee_liang is offline Offline
Newbie Poster

Re: Design idea?

 
0
  #2
Nov 19th, 2008
basically what you need to do is simply just like you are building any desktop application. you need to have a connection with your database which in this case is using JDBC since you are developing a web using JSP. Once you have created the connection between you web and database you can start do any kind of action to do the interaction between your web and database. here's a basic login example to give you some basic clue.

your_login_form.jsp
  1.  
  2. <table width="982" height="543" border="0" align="center" class="table">
  3. <form id="login" name="login" method="post" action="doLogin.jsp">
  4. <tr>
  5. <td align="center" valign="middle"><table width="212" height="286" border="0">
  6. <tr>
  7. <td height="135" align="left" valign="bottom"><input name="username" type="text" class="field_bg" maxlength="15"/></td>
  8. </tr>
  9. <tr>
  10. <td height="65" align="left" valign="bottom"><input name="password" type="password" class="field_bg" maxlength="15"/></td>
  11. </tr>
  12. <tr>
  13. <td height="73" align="right" valign="bottom"><input type="submit" name="Submit" value="" class="button_bg" /></td>
  14. </tr>
  15. </table></td>
  16. </tr>
  17. </form>
  18. </table>


doLogin.jsp
  1.  
  2. <%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %>
  3. <%
  4. String name = request.getParameter("Username");
  5. String pass = request.getParameter("Password");
  6.  
  7. Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  8. Connection con = DriverManager.getConnection("jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=" + application.getRealPath("WEB-INF/db.mdb"));
  9. Statement stmt = con.createStatement(1004,1008) ;
  10. ResultSet rs = stmt.executeQuery("Select * from MsUser where username='" + name + "' and password ='" + pass + "'");
  11. Boolean exist = rs.first();
  12. if(exist == true)
  13. {
  14. session.setAttribute("__IN",rs.getString("username"));
  15. con.close();
  16. response.sendRedirect("index.jsp");
  17. }
  18. else
  19. out.print("Login Failed");
  20.  
  21. %>
Last edited by peter_budo; Nov 20th, 2008 at 6:07 am. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 4,191
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 485
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: Design idea?

 
-1
  #3
Nov 20th, 2008
Originally Posted by sundar divas View Post
Please help me to start....
What about a search of the forum? Any useful results?

@vee_liang - connecting to DB from JSP is worst possible scenario. You should look at MVC model2
Last edited by peter_budo; Nov 20th, 2008 at 6:11 am.
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 16
Reputation: vee_liang is an unknown quantity at this point 
Solved Threads: 1
vee_liang vee_liang is offline Offline
Newbie Poster

Re: Design idea?

 
0
  #4
Nov 23rd, 2008
@peter_budo Thank's for the info. Really appreciate it.
Vee Liang
To be right, first you have to know what wrong is.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the JSP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC