package com.test.userdao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import com.test.conn.Conn;
public class UserDao {
public ResultSet doDenglu_Student(String Student_name,String Student_password){
ResultSet rs=null;
try {
Conn dbc=new Conn();
Connection conn=dbc.getConn();
String sql_DoDenglu_Student="select *from student where Student_name='"+Student_name+"' and Student_password='"+Student_password+"'";
PreparedStatement pst=conn.prepareStatement(sql_DoDenglu_Student);
rs=pst.executeQuery();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return rs;
}
public ResultSet doDenglu_Teacher(String Teacher_name,String Teacher_password){
ResultSet rs=null;
try {
Conn dbc=new Conn();
Connection conn=dbc.getConn();
String sql_DoDenglu_Teacher="select *from teacher where Teacher_name='"+Teacher_name+"' and Teacher_password='"+Teacher_password+"'";
PreparedStatement pst=conn.prepareStatement(sql_DoDenglu_Teacher);
rs=pst.executeQuery();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return rs;
}
public int insert_Student(String Student_name,String Student_password,String Student_xueli,String Student_phone,String Student_email){
int rs=0;
try {
Conn dbc=new Conn();
Connection conn=dbc.getConn();
String sql_insert_student="insert into student(Student_name,Student_password,Student_xueli,Student_phone,Student_email) values(?,?,?,?,?)";
PreparedStatement pst=conn.prepareStatement(sql_insert_student);
pst.setString(1,Student_name);
pst.setString(2,Student_password);
pst.setString(3,Student_xueli);
pst.setString(4,Student_phone);
pst.setString(5,Student_email);
rs=pst.executeUpdate();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return rs;
}
public ResultSet select_Student(String Student_id){
ResultSet rs=null;
try {
Conn dbc=new Conn();
Connection conn=dbc.getConn();
String sql_select_Student="select * from student where Student_id="+Student_id+"";
PreparedStatement pst=conn.prepareStatement(sql_select_Student);
rs=pst.executeQuery();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return rs;
}
public ResultSet update_Student(String Student_id){
ResultSet rs=null;
try {
Conn dbc=new Conn();
Connection conn=dbc.getConn();
String sql_update_Student="select * from student where Student_id="+Student_id+"";
PreparedStatement pst=conn.prepareStatement(sql_update_Student);
rs=pst.executeQuery();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return rs;
}
public int doupdate_Student(String Student_name,String Student_password,String Student_xueli,String Student_phone,String Student_email,String Student_id){
int rs=0;
try {
Conn dbc=new Conn();
Connection conn=dbc.getConn();
String sql_doupdate_Student="update student set Student_name='"+Student_name+"',Student_password='"+Student_password+"',Student_xueli='"+Student_xueli+"',Student_phone='"+Student_phone+"',Student_email='"+Student_email+"'" +
" where Student_id="+Student_id+"";
PreparedStatement pst=conn.prepareStatement(sql_doupdate_Student);
rs=pst.executeUpdate();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return rs;
}
public int insert_Xiangmu(String Xiangmu_name,String Xiangmu_jianjie,String Xiangmu_time,String Student_name){
int rs=0;
try {
Conn dbc=new Conn();
Connection conn=dbc.getConn();
String sql_insert_Xiangmu="insert into xiangmu(Xiangmu_name,Xiangmu_ping,Xiangmu_jianjie,Xiangmu_time,Student_name,Xiangmu_zhi) values(?,?,?,?,?,?)";
PreparedStatement pst=conn.prepareStatement(sql_insert_Xiangmu);
pst.setString(1, Xiangmu_name);
pst.setString(2, null);
pst.setString(3, Xiangmu_jianjie);
pst.setString(4, Xiangmu_time);
pst.setString(5, Student_name);
pst.setString(6, null);
rs=pst.executeUpdate();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return rs;
}
public ResultSet select_Xiangmu(String keyword){
ResultSet rs=null;
try {
Conn dbc=new Conn();
Connection conn=dbc.getConn();
String sql_select_Xiangmu="select *from xiangmu where Xiangmu_name Like '%"+ keyword + "%'or Xiangmu_id Like '%"+ keyword + "%'or Student_name Like '%"+ keyword + "%'or Teacher_name Like '%"+ keyword + "%' ";
PreparedStatement pst=conn.prepareStatement(sql_select_Xiangmu);
rs=pst.executeQuery();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return rs;
}
public ResultSet select_XM(String Xiangmu_id){
ResultSet rs=null;
try {
Conn dbc=new Conn();
Connection conn=dbc.getConn();
String sql_select_XM="select * from xiangmu where Xiangmu_id="+Xiangmu_id+"";
PreparedStatement pst=conn.prepareStatement(sql_select_XM);
rs=pst.executeQuery();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return rs;}
public String Date(){
String dateTime;
Date currDate = Calendar.getInstance().getTime();
SimpleDateFormat sdf=new SimpleDateFormat("yyyy.MM.dd. HH:mm.ss");
dateTime=sdf.format(currDate);
return dateTime;
}
public ResultSet select_TeacherXM(){
ResultSet rs=null;
try {
Conn dbc=new Conn();
Connection conn=dbc.getConn();
String sql_select_TeacherXM="select * from Xiangmu";
PreparedStatement pst=conn.prepareStatement(sql_select_TeacherXM);
rs=pst.executeQuery();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return rs;
}
public ResultSet update_XMTeacher(String Xiangmu_id){
ResultSet rs=null;
try {
Conn dbc=new Conn();
Connection conn=dbc.getConn();
String sql_update_XMTeacher="select Xiangmu_ping,Xiangmu_zhi from xiangmu where Xiangmu_id="+Xiangmu_id+"";
PreparedStatement pst=conn.prepareStatement(sql_update_XMTeacher);
rs=pst.executeQuery();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return rs;
}
public int doupdate_XMTeacher(String Xiangmu_ping,String Xiangmu_zhi,String Teacher_name,String Xiangmu_id){
int rs=0;
try {
Conn dbc=new Conn();
Connection conn=dbc.getConn();
String sql_doupdate_XMTeacher="update xiangmu set Xiangmu_ping='"+Xiangmu_ping+"',Xiangmu_zhi='"+Xiangmu_zhi+"',Teacher_name='"+Teacher_name+"' where Xiangmu_id="+Xiangmu_id+"";
PreparedStatement pst=conn.prepareStatement(sql_doupdate_XMTeacher);
rs=pst.executeUpdate();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return rs;
}
public ResultSet select_Teacher(String Teacher_id){
ResultSet rs=null;
try {
Conn dbc=new Conn();
Connection conn=dbc.getConn();
String sql_select_Teacher="select * from teacher where Teacher_id="+Teacher_id+"";
PreparedStatement pst=conn.prepareStatement(sql_select_Teacher);
rs=pst.executeQuery();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return rs;
}
public ResultSet update_Teacher(String Teacher_id){
ResultSet rs=null;
try {
Conn dbc=new Conn();
Connection conn=dbc.getConn();
String sql_update_Teacher="select * from teacher where Teacher_id="+Teacher_id+"";
PreparedStatement pst=conn.prepareStat