📄 regstudent.java
字号:
import java.util.*;
import java.util.Vector;
import java.io.*;
import java.sql.*;
public class RegStudent
{
private Connection aConnection;
private Statement aStatement;
private String id;
private String age;
private String sex;
private String name;
private String password;
private String place;
private String department;
private String classname;
public RegStudent()
{
initialize();
}
public void initialize()
{
String url="jdbc:odbc:StudentAdministrator";
String driver="sun.jdbc.odbc.JdbcOdbcDriver";
try
{
Class.forName(driver);
aConnection=DriverManager.getConnection(url,"","");
aStatement=aConnection.createStatement();
}
catch(ClassNotFoundException e)
{ System.out.println(e); }
catch(SQLException e)
{ System.out.println(e); }
}
public Student findStudent(Student s)throws NotFoundException
{
//好像多余此方法
String stuid=s.getStudId();
Student aStudent=null;
String sqlQuery="select * from student where studId='"+stuid+"'";
try
{
ResultSet rs=aStatement.executeQuery(sqlQuery);
boolean gotIt=rs.next();
if(gotIt)
{
id=rs.getString(1);
password=rs.getString(2);
name=rs.getString(3);
sex=rs.getString(4);
age=rs.getString(5);
place=rs.getString(6);
classname=rs.getString(7);
department=rs.getString(8);
aStudent=new Student(id,password,name,sex,age,place,classname,department);
}
else
{ throw(new NotFoundException()); }
rs.close();
}
catch(SQLException e)
{ System.out.println(e); System.out.println("错误一"); }
return aStudent;
}
public Student otherFindStudent(String s1,String s2)throws NotFoundException
{
String stuid=s1;
String stupwd=s2;
Student aStudent=null;
String sqlQuery="select * from student where studId='"+stuid+"' and studPwd='"+stupwd+"'";
try
{
ResultSet rs=aStatement.executeQuery(sqlQuery);
boolean gotIt=rs.next();
if(gotIt)
{
id=rs.getString(1);
password=rs.getString(2);
name=rs.getString(3);
sex=rs.getString(4);
age=rs.getString(5);
place=rs.getString(6);
classname=rs.getString(7);
department=rs.getString(8);
aStudent=new Student(id,password,name,sex,age,place,classname,department);
}
else
{ throw(new NotFoundException()); }
rs.close();
}
catch(SQLException e)
{ System.out.println(e); System.out.println("错误一"); }
return aStudent;
}
public Teacher otherFindTeacher(String s1,String s2)throws NotFoundException
{
String teachid=s1;
String teachpwd=s2;
Teacher aTeacher=null;
String sqlQuery="select * from teacher where teachId='"+teachid+"' and teachPwd='"+teachpwd+"'";
try
{
ResultSet rs=aStatement.executeQuery(sqlQuery);
boolean gotIt=rs.next();
if(gotIt)
{
id=rs.getString(1);
password=rs.getString(2);
name=rs.getString(3);
sex=rs.getString(4);
classname=rs.getString(5);
department=rs.getString(6);
aTeacher=new Teacher(id,password,name,sex,classname,department);
}
else
{ throw(new NotFoundException()); }
rs.close();
}
catch(SQLException e)
{ System.out.println(e); System.out.println("错误一"); }
return aTeacher;
}
public ClassDirect otherFindClassDirect(String s1,String s2)throws NotFoundException
{
String classDirectId=s1;
String classDirectPwd=s2;
ClassDirect aClassDirect=null;
String sqlQuery="select * from classDirect where classDirectId='"+classDirectId+"' and classDirectPwd='"+classDirectPwd+"'";
try
{
ResultSet rs=aStatement.executeQuery(sqlQuery);
boolean gotIt=rs.next();
if(gotIt)
{
id=rs.getString(1);
password=rs.getString(2);
name=rs.getString(3);
sex=rs.getString(4);
age=rs.getString(5);
classname=rs.getString(6);
department=rs.getString(7);
aClassDirect=new ClassDirect(id,password,name,sex,age,classname,department);
}
else
{ throw(new NotFoundException()); }
rs.close();
}
catch(SQLException e)
{ System.out.println(e); System.out.println("错误一"); }
return aClassDirect;
}
public Assistant otherFindAssistant(String s1,String s2)throws NotFoundException
{
Assistant aAssistant=null;
String sqlQuery="select * from Assistant where assistantId='"+s1+"' and assistantPwd='"+s2+"'";
try
{
ResultSet rs=aStatement.executeQuery(sqlQuery);
boolean gotIt=rs.next();
if(gotIt)
{
id=rs.getString(1);
password=rs.getString(2);
name=rs.getString(3);
sex=rs.getString(4);
department=rs.getString(5);
aAssistant=new Assistant(id,password,name,sex,department);
}
else
{ throw(new NotFoundException()); }
rs.close();
}
catch(SQLException e)
{ System.out.println(e); System.out.println("错误一"); }
return aAssistant;
}
public Student findStudent(String s1)throws NotFoundException
{
String stuid=s1;
Student aStudent=null;
String sqlQuery="select * from student where studId='"+stuid+"'";
try
{
ResultSet rs=aStatement.executeQuery(sqlQuery);
boolean gotIt=rs.next();
if(gotIt)
{
}
else
{ throw(new NotFoundException()); }
rs.close();
}
catch(SQLException e)
{ System.out.println(e); System.out.println("错误一"); }
return aStudent;
}
public void update(String s1,String s2,String s3,String s4,String s5,String s6,String s7,String s8)
{
String sqlUpdate="Update student set studPwd='"+s2+"',studName='"+s3+
"',studSex='"+s4+"',studAge='"+s5+"',studPlace='"+s6+"',studClassNo='"+s7+"',studPartmentNo='"+s8+"' where studId='"+s1+"'";
try
{
int result=aStatement.executeUpdate(sqlUpdate);
}
catch (SQLException ex)
{
ex.printStackTrace();
}
}
public void updateClassDirect(String s1,String s2,String s3,String s4,String s5,String s6,String s7)
{
String sqlUpdate="Update classDirect set classDirectPwd='"+s2+"',classDirectName='"+s3+
"',classDirectSex='"+s4+"',classDirectTitle='"+s5+"',classDirectClassNo='"+s6+"',classDirectPartmentNo='"+s7+"' where classDirectId='"+s1+"'";
try
{
int result=aStatement.executeUpdate(sqlUpdate);
}
catch (SQLException ex)
{
ex.printStackTrace();
}
}
public void updateTeacher(String s1,String s2,String s3,String s4,String s5,String s6)
{
String sqlUpdate="Update teacher set teachPwd='"+s2+"',teachName='"+s3+
"',teachSex='"+s4+"',teachTitle='"+s5+"',teachPartmentNo='"+s6+"' where teachId='"+s1+"'";
try
{
int result=aStatement.executeUpdate(sqlUpdate);
}
catch (SQLException ex)
{
ex.printStackTrace();
}
}
public void updateAssitant(String s1,String s2,String s3,String s4,String s5)
{
String sqlUpdate="Update assistant set assistantPwd='"+s2+"',assistantName='"+s3+
"',assistantSex='"+s4+"',assistantPartmentNo='"+s5+"' where assistantId='"+s1+"'";
try
{
int result=aStatement.executeUpdate(sqlUpdate);
}
catch (SQLException ex)
{
ex.printStackTrace();
}
}
public void addStudent(Student s)
{
String aid=s.getStudId();
String apwd=s.getStudPwd();
String aname=s.getStudName();
String asex=s.getStudSex();
String aage=s.getStudAge();
String aplace=s.getStudPlace();
String adepartment=s.getStudPartmentNo();
String aclassname=s.getStudClassNo();
String sqlQuery="insert into student "+
"values('"+aid+"','"+apwd+"','"+aname+"','"+asex+"','"+aage+"','"+aplace+"','"+aclassname+"','"+adepartment+"')";
try
{ int result=aStatement.executeUpdate(sqlQuery); }
catch(SQLException e)
{ }
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -