求用JSP做的登陆,连接数据库(SQL2000),查询数据库,添加、修改、删除
展开全部
<%
String no=new String();
no=request.getParameter("no");
String psw=new String();
psw=request.getParameter("psw");
Connection con=null;
Statement sql=null;
ResultSet rs=null;
try {Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); }
catch(ClassNotFoundException e){}
try{con=DriverManager.getConnection("jdbc:odbc:sun","sa","密码");
sql=con.createStatement();
String condition="select * from studentInfo where sid= "+"'"+no+"'"+" and psw= "+"'"+psw+"'";
rs=sql.executeQuery(condition);
if(rs.next()==false)
{out.println("密码或用户名不正确!您现在是游客身份!");}
else {out.println("登陆成功,欢迎您,"+rs.getString("name"));}
con.close();
}
catch(SQLException e1){}
%>
下面是注册的代码,字段视具体情况定:
<%
request.setCharacterEncoding("GBK");
String uname=new String();
String num=new String();
String psw=new String();
String psw1=new String();
String sex=new String();
String clas=new String();
String email=new String();
psw1=request.getParameter("psw1");
uname=request.getParameter("uname");
num=request.getParameter("num");
psw=request.getParameter("psw");
sex=request.getParameter("sex");
email=request.getParameter("email");
clas=request.getParameter("uclas");
if(num.equals("")){out.println("学号不能为空!"+"<p>");}
if(uname.equals("")) {
out.println("姓名不能为空!"+"<p>");}
if(email.indexOf("@")==-1 || email.indexOf("@")==0) {out.println("邮件地址不合法!"+"<p>");}
if(psw.equals("") || psw.equals("")){out.println("密码不能为空!"+"<p>");}
if(clas.equals("class0")) {out.println("请选择一个班级!"+"<p>");}
if(!(psw.equals(psw1))){out.println("两次密码不一致!"+"<p>");}
if((num.length()*uname.length()*psw.length()*psw1.length()*email.length()*sex.length())!=0 && (clas.equals("class0")==false) && psw.equals(psw1))
{ Connection con=null;
Statement sql=null;
ResultSet rs=null;
try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e){}
try{con=DriverManager.getConnection("jdbc:odbc:sun","sa","123jkl");
sql=con.createStatement();
String query1="select * from studentInfo where sid= "+"'"+num+"'";
rs=sql.executeQuery(query1);
if(rs.next()==true){out.println("该学号的用户已存在!");}
else
{String condition="INSERT INTO studentInfo VALUES"
+"("+"'"+num+"','"+uname+"','"+clas+"','"+sex+"','"+psw+"','"+email+"'"+")";
sql.executeUpdate(condition);
out.println("恭喜您!注册成功!");
}
con.close();
}
catch(SQLException e1){out.println("我没有驱动程序");}
}
else out.println("注册失败!");
%>
String no=new String();
no=request.getParameter("no");
String psw=new String();
psw=request.getParameter("psw");
Connection con=null;
Statement sql=null;
ResultSet rs=null;
try {Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); }
catch(ClassNotFoundException e){}
try{con=DriverManager.getConnection("jdbc:odbc:sun","sa","密码");
sql=con.createStatement();
String condition="select * from studentInfo where sid= "+"'"+no+"'"+" and psw= "+"'"+psw+"'";
rs=sql.executeQuery(condition);
if(rs.next()==false)
{out.println("密码或用户名不正确!您现在是游客身份!");}
else {out.println("登陆成功,欢迎您,"+rs.getString("name"));}
con.close();
}
catch(SQLException e1){}
%>
下面是注册的代码,字段视具体情况定:
<%
request.setCharacterEncoding("GBK");
String uname=new String();
String num=new String();
String psw=new String();
String psw1=new String();
String sex=new String();
String clas=new String();
String email=new String();
psw1=request.getParameter("psw1");
uname=request.getParameter("uname");
num=request.getParameter("num");
psw=request.getParameter("psw");
sex=request.getParameter("sex");
email=request.getParameter("email");
clas=request.getParameter("uclas");
if(num.equals("")){out.println("学号不能为空!"+"<p>");}
if(uname.equals("")) {
out.println("姓名不能为空!"+"<p>");}
if(email.indexOf("@")==-1 || email.indexOf("@")==0) {out.println("邮件地址不合法!"+"<p>");}
if(psw.equals("") || psw.equals("")){out.println("密码不能为空!"+"<p>");}
if(clas.equals("class0")) {out.println("请选择一个班级!"+"<p>");}
if(!(psw.equals(psw1))){out.println("两次密码不一致!"+"<p>");}
if((num.length()*uname.length()*psw.length()*psw1.length()*email.length()*sex.length())!=0 && (clas.equals("class0")==false) && psw.equals(psw1))
{ Connection con=null;
Statement sql=null;
ResultSet rs=null;
try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e){}
try{con=DriverManager.getConnection("jdbc:odbc:sun","sa","123jkl");
sql=con.createStatement();
String query1="select * from studentInfo where sid= "+"'"+num+"'";
rs=sql.executeQuery(query1);
if(rs.next()==true){out.println("该学号的用户已存在!");}
else
{String condition="INSERT INTO studentInfo VALUES"
+"("+"'"+num+"','"+uname+"','"+clas+"','"+sex+"','"+psw+"','"+email+"'"+")";
sql.executeUpdate(condition);
out.println("恭喜您!注册成功!");
}
con.close();
}
catch(SQLException e1){out.println("我没有驱动程序");}
}
else out.println("注册失败!");
%>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询