use student id as primary key instead.

This commit is contained in:
Sola
2015-11-26 15:58:56 +08:00
parent c2b2f89805
commit c0f72f4d70
8 changed files with 136 additions and 23 deletions

View File

@@ -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;
}
}