package Dao;
import java.sql.*;
public class User {
private Connection con=null;
private Statement st=null;
private PreparedStatement ps=null;
private ResultSet rs=null;
public final static String driver="com.mysql.jdbc.Driver";
public final static String uri="jdbc:mysql://localhost:3306/News";
public final static String name="root";
public final static String password="123456";
//������ݿ�����
public void getConn(){
try{
Class.forName(driver); //��������
con=DriverManager.getConnection(uri, name, password);
System.out.println("��ݿ�������");
}
catch (ClassNotFoundException e) {
// TODO: handle exception
System.out.println("����δ�ҵ�"+e.toString());
}
catch (SQLException e) {
// TODO: handle exception
System.out.println("���Ӷ���ʧ��"+e.toString());
}
}
//������ݱȶ�
public boolean findNamePassword(String name,String pwd){
boolean flag=false;
String sql="select * from User where name=? and pwd=?";
try{
ps=con.prepareStatement(sql);
ps.setString(1,name);
ps.setString(2, pwd);
rs=ps.executeQuery();
if (rs.next()) {
System.out.println("�û�����");
flag=true;
}
else{
System.out.println("�û�������");
flag=false;
}
}
catch (SQLException e) {
// TODO: handle exception
e.printStackTrace();
}
return flag;
}
//��ȡ�û���
public boolean findName(String name){
boolean flag=false;
String sql="select * from User where name=?";
try{
ps=con.prepareStatement(sql);
ps.setString(1,name);
rs=ps.executeQuery();
if(rs.next()){
System.out.println("�û�����");
flag=true;
}
else{
System.out.println("�û�������");
flag=false;
}
}
catch (SQLException e) {
// TODO: handle exception
e.printStackTrace();
}
return flag;
}
//��ѯ�û����
public boolean findID(int uid){
boolean flag=false;
String sql="select * from User where uid=?";
try{
ps=con.prepareStatement(sql);
ps.setInt(1,uid);
rs=ps.executeQuery();
if(rs.next()){
System.out.println("uid����");
flag=true;
}
else{
System.out.println("uid������");
flag=false;
}
}
catch (SQLException e) {
// TODO: handle exception
e.printStackTrace();
}
return flag;
}
//�û�ע��
public int insertUser(String name,String pwd,String mail){
int i=0;
String sql="insert into User(name,pwd,mail)values(?,?,?)";
try{
ps=con.prepareStatement(sql);
ps.setString(1, name);
ps.setString(2, pwd);
ps.setString(3, mail);
i=ps.executeUpdate();
}
catch (SQLException e) {
// TODO: handle exception
e.printStackTrace();
}
return i;
}
//�û�ע��
public void delete(int uid){
String sql="delete from User where uid=? ";
try{
ps=con.prepareStatement(sql);
ps.setInt(1, uid);
ps.executeUpdate();
}
catch (SQLException e) {
// TODO: handle exception
e.printStackTrace();
}
}
//�û���Ϣ����
public void update(String name,String pwd){
String sql="update User set pwd=? where name=?";
try{
ps=con.prepareStatement(sql);
ps.setString(1, pwd);
ps.setString(2, name);
ps.executeUpdate();
System.out.println("��Ϣ���³ɹ�");
}
catch (SQLException e) {
// TODO: handle exception
e.printStackTrace();
}
}
}
最近下载更多
qwqwx585160 LV2
2024年12月15日
wzd031105 LV2
2024年12月6日
lmj12345 LV2
2024年8月19日
cong58cong LV8
2024年6月26日
bankroll LV5
2024年6月13日
Waner111 LV1
2024年1月4日
asddwh LV13
2023年12月26日
zj20020510 LV5
2023年9月24日
monolog LV4
2023年4月18日
whq12138 LV3
2023年1月6日
最近浏览更多
光明正大黑小虎
6月19日
暂无贡献等级
krispeng LV15
5月29日
1623785086
5月5日
暂无贡献等级
qwqwx585160 LV2
2024年12月15日
traume
2024年12月11日
暂无贡献等级
lyh1989 LV34
2024年12月10日
wzd031105 LV2
2024年12月6日
ChanLain LV2
2024年11月30日
yimaoermao LV1
2024年11月28日
yyhrhv LV8
2024年9月3日

