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....

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

<table width="982" height="543" border="0" align="center" class="table">
<form id="login" name="login" method="post" action="doLogin.jsp">
  <tr>
    <td align="center" valign="middle"><table width="212" height="286" border="0">
      <tr>
        <td height="135" align="left" valign="bottom"><input name="username" type="text" class="field_bg" maxlength="15"/></td>
      </tr>
      <tr>
        <td height="65" align="left" valign="bottom"><input name="password" type="password" class="field_bg" maxlength="15"/></td>
      </tr>
      <tr>
        <td height="73" align="right" valign="bottom"><input type="submit" name="Submit" value="" class="button_bg" /></td>
      </tr>
    </table></td>
  </tr>
</form>
</table>

doLogin.jsp

<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %>
<%
	String name = request.getParameter("Username");
	String pass = request.getParameter("Password");
	
	Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
	Connection con = DriverManager.getConnection("jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=" + application.getRealPath("WEB-INF/db.mdb"));
	Statement stmt = con.createStatement(1004,1008) ;
	ResultSet rs = stmt.executeQuery("Select * from MsUser where username='" + name + "' and password ='" + pass + "'");
	Boolean exist = rs.first();
	if(exist == true)
	{
		session.setAttribute("__IN",rs.getString("username"));
		con.close();
		response.sendRedirect("index.jsp");
	}
	else
		out.print("Login Failed");

%>

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

@peter_budo Thank's for the info. Really appreciate it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.