qurey

qurey

hello sir
i have 2 tables,one is user_details and the other is employee.
in user_details i have given a userid varchar(10) primary key,username varchar(20),password varchar(10).This is login process of my proj.And in employee table also i have to give userid,username,password.This is sign up process. when i enter this id,name and password in employee it should automatically store in user_details also.how should i write the query.plz tell me.

thank u
View Answers

May 19, 2010 at 11:37 AM

Hi Friend,

Try the following code:

1)login.jsp:

<html>
<head>
<style>
A:hover {
text-decoration: none;
font-family:arial;
font-size:12px;
color: #000000;
BORDER: none;
}
A {
text-decoration: underline;
font-family:arial;
font-size:12px;
color: #000000;
BORDER: none;
}
</style>
</head>
<body>
<br><br><br>
<form name="loginform" method="post" action="loginmid.jsp" >
<table width="250px" border=0 align="center" style="background-color:ffeeff;">
<tr>
<td colspan=2 align="center" style="font-weight:bold;font-size:20pt;" align="center">User Login</td>
</tr>
<tr>
<td colspan=2>&nbsp;</td>
</tr>
<tr>
<td style="font-size:12pt;" align="center">Login Name</td>
<td><input type="text" name="userName" value=""></td>
</tr>
<tr>
<td style="font-size:12pt;" align="center">Password</td>
<td><input type="password" name="password" value=""></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="Submit" value="Login"></td>
</tr>
<tr>
<td></td>
<td align="right"><a href="register.jsp">New User?</a></td>
</tr>
</table>
</form>
</body>
</html>

2)loginmid.jsp:

<%@ page language="java" import="java.sql.*;"%>
<html>
<body>
<%
String userName = request.getParameter("userName");
String password = request.getParameter("password");
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root";);
Statement st = conn.createStatement();
String strQuery = "select count(*) from user_details where username='"+userName+"' and password='"+password+"'";
ResultSet rs = st.executeQuery(strQuery);
if(rs.next()){
if(rs.getInt(1)>0){
out.println("Welcome "+userName);
}
else{
response.sendRedirect("login.jsp");
}
}
System.out.println("Connected to the database");
conn.close();
System.out.println("Disconnected from database");
} catch (Exception e) {
e.printStackTrace();
}
%>
</body>
</html>

May 19, 2010 at 11:38 AM

continue..

3)register.jsp:

<%@ page import="java.sql.*"%>
<html>
<body>
<br>
<form name="userform" method="post" >
<table width="350px" border=0 align="center" style="background-color:ffeeff;">
<tr><td colspan=2 style="font-weight:bold;font-size:20pt;" align="center">User Registeration</td>
</tr><tr><td colspan=2>&nbsp;</td>
</tr><tr><td>First Name </td>
<td><input type="text" name="firstName" ></td>
</tr><tr><td>Last Name </td>
<td><input type="text" name="lastname"></td>
</tr><tr>
<td>Login Name</td>
<td><input type="text" name="userName" ></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" name="password" ></td>
</tr>
<tr>
<td>Email</td>
<td><input type="text" name="email" ></td>
</tr>
<tr>
<td>Address</td>
<td><textarea name="address" rows=5 cols=25></textarea></td>
</tr>
<tr>
<td>Contact No</td>
<td><input type="text" name="contactNo" ></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="Submit" value="Save"></td>
</tr>
</table>
</form>
</body>
</html>
<%
String fname=request.getParameter("firstName");
String lname=request.getParameter("lastName");
String uname=request.getParameter("userName");
String password=request.getParameter("password");
String email=request.getParameter("email");
String address=request.getParameter("address");
String contact=request.getParameter("contactNo");
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root";);
Statement st = conn.createStatement();
int i=st.executeUpdate("insert into employee(firstname,lastname,username,password,email,address,contactNo) values('"+fname+"','"+lname+"','"+uname+"','"+password+"','"+email+"','"+address+"','"+contact+"')");
int j=st.executeUpdate("insert into user_details(username,password) values('"+uname+"','"+password+"')");
}
catch(Exception e){}
%>

Hope that it will be helpful for you.
Thanks









Related Tutorials/Questions & Answers:
qurey
qurey - SQL
Advertisements
Sql Querie
39 3 old 41 49 write a qurey to get
array
array  How to store the results of mysql query in an array and display the result in web page.? for exemple I need to store the result of following qurey in array: "select distinct(EMPLID)from tblwork where EMPLID not in (select
myfaces,hibernate and spring integration - Hibernate
myfaces,hibernate and spring integration  sorry, in the previous qurey i have mentioned the Wrong URL.the right url is: http://www.roseindia.net/jsf/myfacesspring/downloadcode.shtml the code given in this url : http

Ads