package Server;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import Bean.Information;
import Bean.User;
import DB.ConnectDB;
public class LoginServer {
private static Connection conn = null;
private static PreparedStatement pst = null;
private static ResultSet rs = null;
/**
*
* @param user
* @return IfSuccess
*/
public int Login(User user) {
try {
String sql = "select UserId from login where UserName = '"
+ user.GetUserName() + "' and UserPwd = '"
+ user.GetUserPwd() + "'";
conn = ConnectDB.connOpen();
pst = conn.prepareStatement(sql);
rs = pst.executeQuery();
if (rs != null) {
rs.next();// 将游标的位置移到第一行
String Id = rs.getString("UserId");// 获取第一行 字段名为"UserId"的值
if (Id != null) {
return 1;
}
}
} catch (Exception ex) {
ex.printStackTrace();
} finally {
if (conn != null) {
try {
conn.close();
} catch (SQLException ex) {
ex.printStackTrace();
}
}
}
return 0;
}
/**
* @param sno
* @return IfSuccess
*/
public int Del(int sno) {
try {
String sql = "Update information set Statue = 0 where Sno = " + sno + "";
conn = ConnectDB.connOpen();
pst = conn.prepareStatement(sql);
int r = pst.executeUpdate();
if (r == 1) {
return 1;
}
else{
return 0;
}
} catch (Exception ex) {
ex.printStackTrace();
} finally {
if (conn != null) {
try {
conn.close();
} catch (SQLException ex) {
ex.printStackTrace();
}
}
}
return 0;
}
/**
* @param sno
* @param sname
* @param sgender
* @param sage
* @return IfSuccess
*/
public int modify(int sno,String sname,String sgender,int sage) {
try {
String sql = "Update information set Sno = "+sno+",Sname = '"+sname+"',Sgender = '"+sgender+"',Sage = "+sage+" where Sno = "+sno+" ";
conn = ConnectDB.connOpen();
pst = conn.prepareStatement(sql);
int r = pst.executeUpdate();
if (r == 1) {
return 1;
}
} catch (Exception ex) {
ex.printStackTrace();
} finally {
if (conn != null) {
try {
conn.close();
} catch (SQLException ex) {
ex.printStackTrace();
}
}
}
return 0;
}
/**
*
*
* @param info
* @return
*/
public int Add(Information info) {
try {
int sno = info.GetSno();
String sname = info.GetSname().toString();
String sgender = info.GetSgender().toString();
int sage = info.GetSage();
String sql = "insert into information values(?,?,?,?,?)";
conn = ConnectDB.connOpen();
pst = conn.prepareStatement(sql);
pst.setInt(1, sno);
pst.setString(2, sname);
pst.setString(3, sgender);
pst.setInt(4, sage);
pst.setInt(5, 1);
int r = pst.executeUpdate();
if (r == 1) {
return 1;
}
} catch (Exception ex) {
ex.printStackTrace();
} finally {
if (conn != null) {
try {
conn.close();
} catch (SQLException ex) {
ex.printStackTrace();
}
}
}
return 0;
}
/**
*
* @return 查询的结果集
*/
public static List<Information> GetAllinfo() {
List<Information> list = new ArrayList<Information>();
try {
String sql = "select Sno,Sname,Sgender,Sage from information where Statue = 1";
conn = ConnectDB.connOpen();
pst = conn.prepareStatement(sql);
rs = pst.executeQuery();// rs是结果集
while (rs.next()) {
Information info = new Information();
info.SetSno(rs.getInt("Sno"));
info.SetSname(rs.getString("Sname"));
info.SetSgender(rs.getString("Sgender"));
info.SetSage(rs.getInt("Sage"));
list.add(info);
}
return list;
} catch (Exception ex) {
ex.printStackTrace();
} finally {
if (conn != null) {
try {
conn.close();
} catch (SQLException ex) {
ex.printStackTrace();
}
}
}
return list;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
MD5加密的登陆.rar (27个子文件)
有验证码和MD5加密的登陆
Train_1
.project 1KB
.mymetadata 294B
src
DB
ConnectDB.java 663B
VerificationCode
BornCode.java 2KB
Controller
UpdateController.java 1KB
DeleteController.java 1023B
LoginController.java 2KB
WelcomeController.java 1KB
Bean
User.java 371B
Information.java 625B
MDD5.java 2KB
Server
LoginServer.java 4KB
WebRoot
WEB-INF
classes
lib
mysql-connector-java-5.0.8-bin.jar 528KB
web.xml 3KB
Styles
Login.css 2KB
Welcom.jsp 3KB
Images
Avcon.png 23KB
loginA.png 3KB
pic.jpg 133KB
aa.jpg 189KB
META-INF
MANIFEST.MF 39B
Js
Jquery-1.8.2.js 260KB
Login.js 2KB
Welcome.js 2KB
Login.jsp 2KB
.myeclipse
.settings
org.eclipse.core.resources.prefs 101B
.classpath 503B
共 27 条
- 1
资源评论
- yixiu1632014-06-25下载了,有些地方看不太懂。感觉还不错。谢谢。
- MrMoneyQ2016-02-16资源很有用,实现了登录时md5加密传输的功能
- 2739719392018-08-07还可以,有用
香草菠萝蜜0916
- 粉丝: 1
- 资源: 6
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功