//显示用户表的主方法
// public static ArrayList selectuser() {
// ArrayList list = new ArrayList();
// String sql = "select * from [user]";
// ResultSet rs = Dao.executeQuery(sql);
// try {
// while (rs.next()) {
// User user = new User();
// user.setName(rs.getString("username"));
// user.setPassword(rs.getString("password"));
// user.setBanji(rs.getString("banji"));
// list.add(user);
// }
// } catch (SQLException ex) {
// Logger.getLogger(Dao.class.getName()).log(Level.SEVERE, null, ex);
// }
// Dao.colse();
// return list;
//
// }
//查询显示用户的方法
public static ArrayList Showuesr() {
ArrayList list = new ArrayList();
String sql = "select * from [user]";
ResultSet rs = Dao.executeQuery(sql);
ResultSetMetaData md = null;
try {
md = rs.getMetaData();
} catch (SQLException ex) {
Logger.getLogger(Dao.class.getName()).log(Level.SEVERE, null, ex);
}
int columnCount = 0;
try {
columnCount = md.getColumnCount();
} catch (SQLException ex) {
Logger.getLogger(Dao.class.getName()).log(Level.SEVERE, null, ex);
}
try {
while (rs.next()) {
Vector map = new Vector();
for (int i = 1; i <= columnCount; i++) {
map.add(rs.getObject(i).toString());
}
list.add(map);
}
} catch (SQLException ex) {
Logger.getLogger(Dao.class.getName()).log(Level.SEVERE, null, ex);
}
return list;
}
/**
*
* @param name
* @param password
* @param banji
* @return
*/
/**
*
* @param name
*
* @param password
* @param banji
* @return
*/
//修改用户的主方法
public static boolean Updateuser(String name, String password, String banji) {
String sql = "update [user] set name=" + name + ",password=" + password + ",banji+" + banji + "'";
if (executeUpdate(sql) != -1) {
return true;
} else {
return false;
}
}
//删除用户的方法
public static boolean Deleteuser(String name) {
String sql = "delect from [user] where 用户名='" + name + "'";
if (executeUpdate(sql) != -1) {
return true;
} else {
return false;
}
}
//增加用户的方法
public static int Adduser(String name, String password, String banji) {
int i = 0;
String sql = "insert into [user](用户名,密码,班级) values ('" + name + "','" + password + "','" + banji + "')";
i = Dao.executeUpdate(sql);
return i;
}
// 注册用户信息
public static int regist(String name, String password, String banji) {
int i = 0;
String sql = "insert into [user](用户名,密码,班级) values ('" + name + "','" + password + "','" + banji + "')";
i = Dao.executeUpdate(sql);
return i;
}
//显示课程表的方法
public static ArrayList ShowTimetable(String banji) {
ArrayList list = new ArrayList();
String sql = "select * from class" + banji;
try {
ResultSet rs = executeQuery(sql);
ResultSetMetaData md = rs.getMetaData();
int columnCount = md.getColumnCount();
while (rs.next()) {
Vector map = new Vector();
for (int i = 1; i <= columnCount; i++) {
if (rs.getObject(i) == null) {
map.add("");
} else {
map.add(rs.getObject(i).toString());
}
}
list.add(map);
}
return list;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
//修改课表的方法
public static boolean UpdateTimetable(String shijian, String keshi, String kecheng, String banji) {
String sql = "update class" + banji + " set " + shijian + "=" + "'" + kecheng + "'where " + "时间=" + "'" + keshi + "'";
if (executeUpdate(sql) != -1) {
return true;
} else {
return false;
}
}
//删除课程的方法
public static boolean DeleteTimetable(String xingqi, String keshi, String kecheng, String banji) {
String sql = "update class" + banji + "set" + xingqi + "=" + "'" + "" + "'where " + "课时=" + "'" + keshi + "'" + "and" + xingqi + "=" + "'" + kecheng + "'";
if (executeUpdate(sql) != -1) {
return true;
} else {
return false;
}
//删掉整行
// String sql = "delect from class_"+banji+" where keshi='" + keshi + "'";
// if (executeUpdate(sql) != -1) {
// return true;
// } else {
// return false;
// }
}
//增加课程的方法,不需这个功能,修改可以实现课程的增加
public static boolean AddTimetable(String xingqi, String keshi, String kecheng, String banji) {
String sql = "insert into class" + banji + "(时间," + xingqi + ") values ('" + keshi + "','" + kecheng + "')";
PreparedStatement pstmt = null;
if (conn == null) {
new Dao();
}
try {
pstmt = (PreparedStatement) conn.prepareStatement(sql);
} catch (SQLException ex) {
Logger.getLogger(Dao.class.getName()).log(Level.SEVERE, null, ex);
}
try {
pstmt.setString(1, keshi);
pstmt.setString(2, kecheng);
} catch (SQLException ex) {
Logger.getLogger(Dao.class.getName()).log(Level.SEVERE, null, ex);
}
try {
pstmt.executeUpdate();
} catch (SQLException ex) {
Logger.getLogger(Dao.class.getName()).log(Level.SEVERE, null, ex);
}
try {
pstmt.close();
} catch (SQLException ex) {
Logger.getLogger(Dao.class.getName()).log(Level.SEVERE, null, ex);
}
return true;
//conn.close();
}
// public static boolean loginResult(String name, String password) throws SQLException {
String sql = "select * from [user] where 用户名='" + name
+ "'and 密码='" + password + "'";
ResultSet rs = Dao.executeQuery(sql);
boolean loginR = false;
try {
while (rs.next()) {
String nameGet = rs.getString("用户名");
String passwordGet = rs.getString("密码");
if (nameGet.equals(name) && passwordGet.equals(password)) {
loginR = true;
break;//跳出当前循环
}
}
} catch (SQLException ex) {
Logger.getLogger(Dao.class.getName()).log(Level.SEVERE, null, ex);
}
Dao.close();
return loginR;
// //当前数据库中的User_Info表中查询
// String sql = "select * from [user] where 用户名='" + name
// + "' and 密码='" + password + "'";
// //返回的结果,包括所有的用户密码(name和password)注册信息
//
// ResultSet rs = Dao.executeQuery(sql);
// boolean loginR = false;
// while (rs.next()) {
// String nameGet = rs.getString("用户名");
// String passwordGet = rs.getString("密码");
// if (nameGet.equals(name) && passwordGet.equals(password)) {
// loginR = true;
// break;//跳出当前循环
// }
// }
// return loginR;
// }
//在当前数据库中的User_Info表中查询
// String sql = "select * from class_"+banji+" where 姓名='" + name
// + "'";
// //返回的结果,包括所有的用户密码(name和password)注册信息
// ResultSet rs1 = Dao.executeQuery(sql);
// boolean loginR = false;
// try {
// //从当前结果集rs中取得需要的信息,并进行比较核对
// while (rs.next()) {
// String nameGet = rs.getString("姓名");
// //String passwordGet = rs.getString("password"); && passwordGet.equals(password)
// if (nameGet.equals(name)) {
// loginR = true;
// break;//跳出当前循环
// }
// }
// } catch (SQLException ex) {
// Logger.getLogger(Dao.class.getName()).log(Level.SEVERE, null, ex);
// }
// Dao.close();
// return loginR;
//从当前结果集rs中取得需要的信息,并进行比较核对
// while (rs.next()) {
// String nameGet = rs.getString("姓名");
// //String passwordGet = rs.getString("password");
// //if (nameGet.equals(name) && passwordGet.equals(password)) {
// if (nameGet.equals(name) ) {
// loginR = true;
// break;//跳出当前循环
// }
// return loginR;
/**
* **********************记得关闭连接通道************************************
*/
public static void close() {
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
} finally {
conn = null;
}
}
// public static ArrayList selectuser() {
// ArrayList list = new ArrayList();
// String sql = "select * from [user]";
// ResultSet rs = Dao.executeQuery(sql);
// try {
// while (rs.next()) {
// User user = new User();
// user.setName(rs.getString("username"));
// user.setPassword(rs.getString("password"));
// user.setBanji(rs.getString("banji"));
// list.add(user);
// }
// } catch (SQLException ex) {
// Logger.getLogger(Dao.class.getName()).log(Level.SEVERE, null, ex);
// }
// Dao.colse();
// return list;
//
// }
//查询显示用户的方法
public static ArrayList Showuesr() {
ArrayList list = new ArrayList();
String sql = "select * from [user]";
ResultSet rs = Dao.executeQuery(sql);
ResultSetMetaData md = null;
try {
md = rs.getMetaData();
} catch (SQLException ex) {
Logger.getLogger(Dao.class.getName()).log(Level.SEVERE, null, ex);
}
int columnCount = 0;
try {
columnCount = md.getColumnCount();
} catch (SQLException ex) {
Logger.getLogger(Dao.class.getName()).log(Level.SEVERE, null, ex);
}
try {
while (rs.next()) {
Vector map = new Vector();
for (int i = 1; i <= columnCount; i++) {
map.add(rs.getObject(i).toString());
}
list.add(map);
}
} catch (SQLException ex) {
Logger.getLogger(Dao.class.getName()).log(Level.SEVERE, null, ex);
}
return list;
}
/**
*
* @param name
* @param password
* @param banji
* @return
*/
/**
*
* @param name
*
* @param password
* @param banji
* @return
*/
//修改用户的主方法
public static boolean Updateuser(String name, String password, String banji) {
String sql = "update [user] set name=" + name + ",password=" + password + ",banji+" + banji + "'";
if (executeUpdate(sql) != -1) {
return true;
} else {
return false;
}
}
//删除用户的方法
public static boolean Deleteuser(String name) {
String sql = "delect from [user] where 用户名='" + name + "'";
if (executeUpdate(sql) != -1) {
return true;
} else {
return false;
}
}
//增加用户的方法
public static int Adduser(String name, String password, String banji) {
int i = 0;
String sql = "insert into [user](用户名,密码,班级) values ('" + name + "','" + password + "','" + banji + "')";
i = Dao.executeUpdate(sql);
return i;
}
// 注册用户信息
public static int regist(String name, String password, String banji) {
int i = 0;
String sql = "insert into [user](用户名,密码,班级) values ('" + name + "','" + password + "','" + banji + "')";
i = Dao.executeUpdate(sql);
return i;
}
//显示课程表的方法
public static ArrayList ShowTimetable(String banji) {
ArrayList list = new ArrayList();
String sql = "select * from class" + banji;
try {
ResultSet rs = executeQuery(sql);
ResultSetMetaData md = rs.getMetaData();
int columnCount = md.getColumnCount();
while (rs.next()) {
Vector map = new Vector();
for (int i = 1; i <= columnCount; i++) {
if (rs.getObject(i) == null) {
map.add("");
} else {
map.add(rs.getObject(i).toString());
}
}
list.add(map);
}
return list;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
//修改课表的方法
public static boolean UpdateTimetable(String shijian, String keshi, String kecheng, String banji) {
String sql = "update class" + banji + " set " + shijian + "=" + "'" + kecheng + "'where " + "时间=" + "'" + keshi + "'";
if (executeUpdate(sql) != -1) {
return true;
} else {
return false;
}
}
//删除课程的方法
public static boolean DeleteTimetable(String xingqi, String keshi, String kecheng, String banji) {
String sql = "update class" + banji + "set" + xingqi + "=" + "'" + "" + "'where " + "课时=" + "'" + keshi + "'" + "and" + xingqi + "=" + "'" + kecheng + "'";
if (executeUpdate(sql) != -1) {
return true;
} else {
return false;
}
//删掉整行
// String sql = "delect from class_"+banji+" where keshi='" + keshi + "'";
// if (executeUpdate(sql) != -1) {
// return true;
// } else {
// return false;
// }
}
//增加课程的方法,不需这个功能,修改可以实现课程的增加
public static boolean AddTimetable(String xingqi, String keshi, String kecheng, String banji) {
String sql = "insert into class" + banji + "(时间," + xingqi + ") values ('" + keshi + "','" + kecheng + "')";
PreparedStatement pstmt = null;
if (conn == null) {
new Dao();
}
try {
pstmt = (PreparedStatement) conn.prepareStatement(sql);
} catch (SQLException ex) {
Logger.getLogger(Dao.class.getName()).log(Level.SEVERE, null, ex);
}
try {
pstmt.setString(1, keshi);
pstmt.setString(2, kecheng);
} catch (SQLException ex) {
Logger.getLogger(Dao.class.getName()).log(Level.SEVERE, null, ex);
}
try {
pstmt.executeUpdate();
} catch (SQLException ex) {
Logger.getLogger(Dao.class.getName()).log(Level.SEVERE, null, ex);
}
try {
pstmt.close();
} catch (SQLException ex) {
Logger.getLogger(Dao.class.getName()).log(Level.SEVERE, null, ex);
}
return true;
//conn.close();
}
// public static boolean loginResult(String name, String password) throws SQLException {
String sql = "select * from [user] where 用户名='" + name
+ "'and 密码='" + password + "'";
ResultSet rs = Dao.executeQuery(sql);
boolean loginR = false;
try {
while (rs.next()) {
String nameGet = rs.getString("用户名");
String passwordGet = rs.getString("密码");
if (nameGet.equals(name) && passwordGet.equals(password)) {
loginR = true;
break;//跳出当前循环
}
}
} catch (SQLException ex) {
Logger.getLogger(Dao.class.getName()).log(Level.SEVERE, null, ex);
}
Dao.close();
return loginR;
// //当前数据库中的User_Info表中查询
// String sql = "select * from [user] where 用户名='" + name
// + "' and 密码='" + password + "'";
// //返回的结果,包括所有的用户密码(name和password)注册信息
//
// ResultSet rs = Dao.executeQuery(sql);
// boolean loginR = false;
// while (rs.next()) {
// String nameGet = rs.getString("用户名");
// String passwordGet = rs.getString("密码");
// if (nameGet.equals(name) && passwordGet.equals(password)) {
// loginR = true;
// break;//跳出当前循环
// }
// }
// return loginR;
// }
//在当前数据库中的User_Info表中查询
// String sql = "select * from class_"+banji+" where 姓名='" + name
// + "'";
// //返回的结果,包括所有的用户密码(name和password)注册信息
// ResultSet rs1 = Dao.executeQuery(sql);
// boolean loginR = false;
// try {
// //从当前结果集rs中取得需要的信息,并进行比较核对
// while (rs.next()) {
// String nameGet = rs.getString("姓名");
// //String passwordGet = rs.getString("password"); && passwordGet.equals(password)
// if (nameGet.equals(name)) {
// loginR = true;
// break;//跳出当前循环
// }
// }
// } catch (SQLException ex) {
// Logger.getLogger(Dao.class.getName()).log(Level.SEVERE, null, ex);
// }
// Dao.close();
// return loginR;
//从当前结果集rs中取得需要的信息,并进行比较核对
// while (rs.next()) {
// String nameGet = rs.getString("姓名");
// //String passwordGet = rs.getString("password");
// //if (nameGet.equals(name) && passwordGet.equals(password)) {
// if (nameGet.equals(name) ) {
// loginR = true;
// break;//跳出当前循环
// }
// return loginR;
/**
* **********************记得关闭连接通道************************************
*/
public static void close() {
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
} finally {
conn = null;
}
}