Latest Tutorials| Questions and Answers|Ask Questions?|Site Map




Have Programming Question? Ask it here!
 
 
 


Ragini Shukla
HIiiiiiiiii
4 Answer(s)      6 years ago
Posted in : Java Beginners



Advertisement
View Answers

August 13, 2008 at 1:58 PM


hai frnd.....
its pleasure to hear that's working well...
then try for this in the same manner by changine the sqlcommand....
thanks and reg/
prashu
prashobvee@gmail.com


August 13, 2008 at 4:13 PM


Hi friend,

Code to solve your problem:

First file "user.jsp"

<%@ page language="java" %>
<%@ page import="java.lang.*" %>
<%@ page import="java.sql.*" %>

<HTML>
<head>
<script>
function deleteUser(){

var id =document.getElementById("vend_id").value;
var url="process.jsp?vend_id="+id;
window.location.href=url;
}
function validate(){


if(document.frm.vend_id.value=="")
{

alert("Please enter Id");
document.frm.vend_id.focus();
return false;
}
}

</script>

</head>
<BODY>
<FORM NAME="frm" METHOD="post" ACTION="addform.jsp" onsubmit="return validate();">
</BR> </BR>

<H3> <P ALIGN="CENTER"> <FONT SIZE=6> Search User</FONT> </P> </H3> </BR>

<TABLE CELLSPACING=5 CELLPADDING=5 border=0 BGCOLOR="LIGHTBLUE" COLSPAN=2 ROWSPAN=2 ALIGN="CENTER" width="400px">

<TR>
<TD> <FONT SIZE=4>Id</TD>
<TD colspan=2><INPUT TYPE="TEXT" NAME="vend_id" id="vend_id"></td>


</TR>

<TR> <FONT SIZE=6>
<TD colspan=3 align="center">
<INPUT TYPE="Submit" name="submit" VALUE="Update">
<INPUT TYPE="button" name="submit" VALUE="Delete" onclick="deleteUser();">

</TD>
</TR> </FONT>

</FORM>
</BODY>
</HTML>


August 13, 2008 at 4:19 PM


"addform.jsp"


<%@ page language="java" %>
<%@ page import="java.lang.*" %>
<%@ page import="java.sql.*" %>
<%
String username="";
String user_pass="";
String firstname="";
String lastname="";
String email="";
String state="";
String city="";
String country="";

Connection conn = null;
String url = "jdbc:mysql://localhost:3306/";;
String dbName = "user_register";
String driver = "com.mysql.jdbc.Driver";
String userName = "root";
String password = "root";

int sumcount=0;
Statement st;
int id = Integer.parseInt(request.getParameter("vend_id").toString());

if(request.getParameter("vend_id")!=null && request.getParameter("vend_id")!="")
{
try {
Class.forName(driver).newInstance();

conn = DriverManager.getConnection(url+dbName,userName,password);
String query = "select * from register where id='"+id+"'";

st = conn.createStatement();
ResultSet rs = st.executeQuery(query);
while(rs.next())
{

username=rs.getString(2);
user_pass=rs.getString(3);
firstname=rs.getString(4);
lastname=rs.getString(5);
email=rs.getString(6);
state=rs.getString(7);
city=rs.getString(8);
country=rs.getString(9);
}

}
catch (Exception e) {
e.printStackTrace();
}
}

%>


August 13, 2008 at 4:23 PM


To delete the record page "process.jsp"

<%@ page import="java.sql.*" %>
<%
int vend_id = Integer.parseInt(request.getParameter("vend_id").toString());
Connection conn = null;
String url = "jdbc:mysql://localhost:3306/";;
String dbName = "user_register";
String driver = "com.mysql.jdbc.Driver";
String userName = "root";
String password = "root";

String query="";
Statement st;
try {
Class.forName(driver).newInstance();
conn = DriverManager.getConnection(url+dbName,userName,password);
query = "delete from register where id='"+vend_id+"'";
st = conn.createStatement();
int i = st.executeUpdate(query);
if(i>0)
{
response.sendRedirect("adduser.jsp");
}
}
catch (Exception e) {
e.printStackTrace();
}

%>


To update the record having a form "addform.jsp".
To delete the record having a "process.jsp".

Thanks

vineet


Related Tutorials/Questions & Answers:
Advertisements
 

 

 

DMCA.com