src/com/tjzhic/dao/impl/StuDaoImpl.java
(开头部分) 5KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
package com.tjzhic.dao.impl;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import com.tjzhic.dao.StuDao;
import com.tjzhic.db.ConnectionFactory;
import com.tjzhic.entity.Stu;
public class StuDaoImpl implements StuDao{
//添加一个新的学生
public int add(Stu stu) {
int rows = 0;
Connection con = ConnectionFactory.getConnection();
PreparedStatement pre = null;
try {
String sql = "insert into stu(username,password,regip,regtime) values(?,?,?,NOW())";
pre = con.prepareStatement(sql);
pre.setString(1, stu.getUsername());
pre.setString(2, stu.getPassword());
pre.setString(3, stu.getRegip());
rows = pre.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
} finally {
try{
if (pre!=null)
pre.close();
if (con != null)
con.close();
}catch (SQLException e) {
e.printStackTrace();
}
}
return rows;
}
//通过用户名查找用户
public Stu findByUsername(String username) {
Stu stu = null;
Connection con = ConnectionFactory.getConnection();
PreparedStatement pre = null;
ResultSet rs = null;
try{
pre = con.prepareStatement("select username,regip,regtime from stu where username=? limit 1");
pre.setString(1, username);
rs = pre.executeQuery();
while(rs.next()){
stu=new Stu();
stu.setUsername(rs.getString(1));
stu.setRegip(rs.getString(2));
stu.setRegtime(rs.getString(3));
}
}catch (Exception e){
e.printStackTrace();
}finally{
后面还有 147 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。