mirror of
https://github.com/ZSCNetSupportDept/WechatTicketSystem.git
synced 2026-02-11 12:49:31 +08:00
use student id as primary key instead.
This commit is contained in:
@@ -18,7 +18,6 @@ public class TableUser extends SQLCore {
|
||||
|
||||
public static final String COLUMN_ID = "id";
|
||||
public static final String COLUMN_NAME = "name";
|
||||
public static final String COLUMN_STUDENT_ID = "studentid";
|
||||
public static final String COLUMN_NET_ACCOUNT = "netaccount";
|
||||
public static final String COLUMN_ISP = "isp";
|
||||
public static final String COLUMN_WECHAT = "wechat";
|
||||
@@ -29,32 +28,51 @@ public class TableUser extends SQLCore {
|
||||
ps.setString(1, name);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
if (rs.next()) {
|
||||
return new User(rs.getInt(COLUMN_ID),
|
||||
return new User(rs.getLong(COLUMN_ID),
|
||||
rs.getString(COLUMN_NAME),
|
||||
rs.getLong(COLUMN_STUDENT_ID),
|
||||
rs.getString(COLUMN_NET_ACCOUNT),
|
||||
ISPType.fromId(rs.getInt(COLUMN_ISP)),
|
||||
rs.getString(COLUMN_WECHAT));
|
||||
}
|
||||
} catch (SQLException e) { }
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static User getUserById(int id) {
|
||||
public static User getUserById(long id) {
|
||||
try (Connection conn = ds.getConnection()) {
|
||||
PreparedStatement ps = conn.prepareStatement("SELECT * FROM user_info WHERE id=?");
|
||||
ps.setInt(1, id);
|
||||
ps.setLong(1, id);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
if (rs.next()) {
|
||||
return new User(rs.getInt(COLUMN_ID),
|
||||
return new User(rs.getLong(COLUMN_ID),
|
||||
rs.getString(COLUMN_NAME),
|
||||
rs.getLong(COLUMN_STUDENT_ID),
|
||||
rs.getString(COLUMN_NET_ACCOUNT),
|
||||
ISPType.fromId(rs.getInt(COLUMN_ISP)),
|
||||
rs.getString(COLUMN_WECHAT));
|
||||
}
|
||||
} catch (SQLException e) { }
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static int updateUser(User user) {
|
||||
try (Connection conn = ds.getConnection()) {
|
||||
PreparedStatement ps = conn.prepareStatement("UPDATE user_info SET " +
|
||||
COLUMN_WECHAT + "=?," +
|
||||
COLUMN_NET_ACCOUNT + "=?," +
|
||||
COLUMN_ISP + "=? " +
|
||||
"WHERE id=?");
|
||||
ps.setString(1, user.getWechatId());
|
||||
ps.setString(2, user.getNetAccount());
|
||||
ps.setInt(3, user.getIsp().id);
|
||||
ps.setLong(4, user.getId());
|
||||
return ps.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user