public AllMethods()throws Exception
{
Class.forName("com.mysql.jdbc.Driver");
String url="jdbc:mysql://localhost:3306/rjgc?useSSL=false&useUnicode=true&characterEncoding=utf8";
String username="root";
String password="qq2665410029";
connect = DriverManager.getConnection(url,username,password);
}
public void finalize() throws Exception
{
connect.close();
}
/*student IsPass
* 学生账号登录判断,判断是否可以登录
* 输入参数为:学号,即id(String);密码,即pass(String)
* 若有此学号信息且密码核对成功,即登录成功,则返回true,若此学号未有记录或密码核对失败或已被删除,即登录失败,则返回false
* */
public boolean stu_IsPass(String id,String pass) throws Exception
{
if(pass!=null)
{
if(!pass.equals(""))
{
if (pass != null) {
if (pass!=null)
return true;
else
return false;
} else
return false;
}
else
return false;
}
else
return false;
}
/* administrators IsPass
* 管理员账号登录判断,判断是否可以登录
* 输入参数为:管理员账号,即id(String);密码,即pass(String)
* 若有此账号信息且密码核对成功,即登录成功,则返回true,若此账号未有记录或密码核对失败或已被删除,即登录失败,则返回false
* */
public boolean root_IsPass(String id,String pass) throws Exception
{
if(pass!=null)
{
if(!pass.equals(""))
{
if (pass != null) {
if (pass!=null)
return true;
else
return false;
} else
return false;
}
else
return false;
}
else
return false;
}
public boolean addstudent(String stuname,String stuid,String stuclass,String stupwd)throws Exception
{
String sql="insert into student values(stuname,stuid,stuclass,stupwd)";
PreparedStatement pre = connect.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);//改成可以改位置
ResultSet rs = pre.executeQuery();
rs.last();//光标移到最后
int rowCount=rs.getRow();//当前行是第几行
rs.beforeFirst();//移回去
examination[] examinations=new examination[rowCount];
int i=0;
while(rs.next())
{
examinations[i]=new examination();
examinations[i].stuid=rs.getString("stuid");
examinations[i].examname=rs.getString("examname");
examinations[i].grade=rs.getInt("grade");
i++;
}
pre.close();
return true;
}