📄 userbean.java
字号:
package com;
import javax.sql.DataSource;
import java.sql.*;
import javax.sql.*;
import java.util.Collection;
import java.util.ArrayList;
import shixun.studentForm;
import shixun.studentScoreForm;
import shixun.studentkzForm;
public class userBean {
private DataSource ds;
private Connection conn;
private PreparedStatement pre;
private ResultSet result;
//验证登陆的办法
public boolean login(DataSource ds,String user,String pass)throws Exception
{
boolean flag=false;
Connection conn=ds.getConnection();
Statement stmt=conn.createStatement();
String sql="select * from users where username='"+user+"'and password='"+pass+"' ";
ResultSet rst=stmt.executeQuery(sql);
while(rst.next()){
flag=true;
}
conn.close();
return flag;
}
//用户更改密码
public boolean updateUserPassword(DataSource ds,String name,String pass) throws Exception
{
boolean flag=false;
Connection conn=ds.getConnection();
try{
Statement stmt=conn.createStatement();
String sql="update users set password='"+pass+"' where username='"+name+"'";
stmt.executeUpdate(sql);
flag=true;
}
catch(Exception e)
{
flag=false;
}
return flag;
}
//返回学生个人的所有信息
public studentForm selectUserInfomation(DataSource ds,String username)throws Exception
{
Connection conn=ds.getConnection();
Statement stmt=conn.createStatement();
String sql="select * from stuinfo where stuno='"+username+"'";
ResultSet rst=stmt.executeQuery(sql);
studentForm temp=new studentForm();
while(rst.next())
{
temp.setName(rst.getString("name"));
temp.setStuno(rst.getString("stuno"));
temp.setClassname(rst.getString("classname"));
temp.setBrithday(rst.getString("brithday"));
temp.setNation(rst.getString("nation"));
temp.setSex(rst.getString("sex"));
temp.setAddress(rst.getString("address"));
temp.setPhone(rst.getString("Phone"));
temp.setSpeciality(rst.getString("speciality"));
}
return temp;
}
//返回学生的成绩信息
public studentScoreForm selectStuScore(DataSource ds,String username) throws Exception
{
Connection conn=ds.getConnection();
Statement stmt=conn.createStatement();
String sql="select * from stuscore where stuno='"+username+"'";
ResultSet rst=stmt.executeQuery(sql);
studentScoreForm temp=new studentScoreForm();
while(rst.next())
{
temp.setStuno(rst.getString("stuno"));
temp.setName(rst.getString("name"));
temp.setClassname(rst.getString("classname"));
temp.setSpeciality(rst.getString("speciality"));
temp.setScore(rst.getString("score"));
temp.setKecheng(rst.getString("kecheng"));
}
return temp;
}
//返回学生的考证信息
public studentkzForm selectStukzScore(DataSource ds,String username) throws Exception
{
Connection conn=ds.getConnection();
Statement stmt=conn.createStatement();
String sql="select * from kzscore where stuno='"+username+"'";
ResultSet rst=stmt.executeQuery(sql);
studentkzForm temp=new studentkzForm();
while(rst.next())
{
temp.setStuno(rst.getString("stuno"));
temp.setName(rst.getString("name"));
temp.setSex(rst.getString("sex"));
temp.setIdnum(rst.getString("idnum"));
temp.setSubject(rst.getString("subject"));
temp.setScore(rst.getString("score"));
}
return temp;
}
//查询数据库中的考证书籍
/* public ResultSet selectkzbook(DataSource ds,String username) throws Exception
{
Connection conn=ds.getConnection();
Statement stmt=conn.createStatement();
String sql="select * from kzbook where subject='"+username+"'";
ResultSet rst=stmt.executeQuery(sql);
return rst;
}
*/
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -