8.14总结

ublic boolean login(string username,string password) throw SQLException{
Connection connection = DBUtil.getconnection();
string sql=“select * from tb_user where username=? and password=?”;
Preparedstatement statement=connection. Preparedstatement (sql);
statement.setString(parameterindex:1,username);
statement.setString(parameterindex:2,password);
Resultset resultset=statement.executeQuery();
if(resultset.next()){
return true;
}else
return false;

ublic boolean zhuce(string username,string password) throws SQLException{
Connection connection=DBUtil.getconnection();
string sql=“insert into tb_user(username,password) values(?,?)”;
preparedStatement statement=connection.prepareStatement(aql);
int i=statement.executeUpdate();
if(i!=0){
return true;
}else
return false;
}

不完整版
新建类user
public class user{
private int id;
private string username;
private string password;

public int getid(){
return id;
}

public void setid(int id){
this;

public class DBUtill{
public static connection getconnection(){
class.forname(“com.mysql.jdbc.drivrr”);
Connection connection=drivermansger.getConnection(url:”……”)
string sql=“select * from tb_user”;
preparedStatement preparedStatement.executeQuery();
while(results.next)
}

public static void

try{
connection=DBUtil.getconnection();
string sql=“select * from tb_user”;
preparedStatement=connection. preparedStatement

public class userdao{
public boolean login(String username,String password) throws SQLException{
Connection connection =DBUtil.getconnection ();
string sql=“select * from tb_user where username=? and password=?”;
PreparedStatement=connection.prepareStatement(sql);
statement.setString(parameter index:1,username);
statement.setString(parameter index:2,password);
ResultSet resultSet=statement.executeQuery();
if(resultSet.next()){
return true;
}else
return false;
}
}

登入注册
system.out.println(“登入失败”);
system.out.println(“请先注册”);
system.out.println(“请输入注册名”);
string zcm=input.next();
system.out.println(“请输入注册密码”);
string zcmm1=input.next();
system.out.println(“请确认密码”);
string zcmm2=input.next();
if(zcmm1==zcmm2){
userDao.zhuce(username,password);
}else{
system.out.println(“密码有误,请重新”);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值