📄 xueshengbean.java
字号:
{
e.printStackTrace();
}
}
return str;
}
//更改密码
public String modifyPassword(String studentId,String oldPassword,String newPassword)
{
PreparedStatement pstmt=null;
ResultSet rst=null;
String str="";
try{
rst=executeQuery("select studentId from xuesheng where studentId='"+studentId+"' and password='"+oldPassword+"'");
if(!rst.next()){
str="wrong";//密码错误
}
else
{
pstmt=con.prepareStatement("update xuesheng set password=? where studentId=?");
pstmt.setString(1,newPassword);
pstmt.setString(2,studentId);
pstmt.execute();
str="sucess";//密码修改成功
}
}catch(SQLException ex)
{
System.err.println(ex.getMessage());
str="failer";//密码修改失败
}
finally
{
try{
if(rst!=null){
rst.close();
}
if(pstmt!=null){
pstmt.close();
}
if(con!=null){
con.close();
}
}catch(Exception e)
{
e.printStackTrace();
}
}
return str;
}
//查询
public ResultSet executeQuery(String sql)
{
Statement stmt=null;
ResultSet rst=null;
try{
stmt=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
rst=stmt.executeQuery(sql);
}catch(SQLException ex)
{
System.err.println(ex.getMessage());
}
return rst;
}
//
public ResultSet getInfo(String sql)
{
ResultSet rst=null;
CallableStatement calStmt=null;
String strSQL="{call pro_allInfo(?)}";
try{
calStmt=con.prepareCall(strSQL);
calStmt.setString(1,sql);
rst=calStmt.executeQuery();
}catch(SQLException ex)
{
System.err.println(ex.getMessage());
}
return rst;
}
//学生信息
public Xuesheng getXuesheng(String studentId) {
Xuesheng xuesheng = null;
PreparedStatement pstmt=null;
ResultSet rst=null;
try {
pstmt = con.prepareStatement(
"select * from xuesheng where studentId='" + studentId +"'");
rst = pstmt.executeQuery();
while (rst.next()) {
xuesheng = new Xuesheng();
xuesheng.setSpeciality(rst.getString("speciality"));
xuesheng.setStuClass(rst.getString("stuClass"));
xuesheng.setStuName(rst.getString("stuName"));
xuesheng.setStuSex(rst.getString("stuSex"));
xuesheng.setBirthDate(rst.getString("birthDate"));
xuesheng.setJiguan(rst.getString("jiguan"));
xuesheng.setShenfenId(rst.getString("shenfenId"));
xuesheng.setJiatingTelphone(rst.getString("jiatingTelphone"));
xuesheng.setStuNation(rst.getString("stuNation"));
xuesheng.setXueLi(rst.getString("xueLi"));
xuesheng.setPhoto(rst.getString("photo"));
xuesheng.setDormId(rst.getString("dormId"));
xuesheng.setStuSource(rst.getString("stuSource"));
xuesheng.setZhenzmmao(rst.getString("zhenzmmao"));
xuesheng.setJiatingAddress(rst.getString("jiatingAddress"));
xuesheng.setStuTelphone(rst.getString("stuTelphone"));
xuesheng.setPostID(rst.getString("postID"));
xuesheng.setBeizu(rst.getString("beizu"));
}
} catch (Exception ex) {
}
finally
{
try{
if (rst != null) {
rst.close();
}
if(pstmt!=null){
pstmt.close();
}
if(con!=null){
con.close();
}
}catch(Exception e)
{
e.printStackTrace();
}
}
return xuesheng;
}
//关闭
public void close()
{
try{
if(con!=null){
con.close();
}
}
catch(SQLException e)
{
e.printStackTrace();
}
}
//所有班级
public String getAllClass()
{
Statement stmt = null;
ResultSet rst = null;
StringBuffer sBuf=new StringBuffer();
try {
stmt=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
rst=stmt.executeQuery("select distinct classId,className from banji");
while(rst.next()) {
String classId= rst.getString("classId");
String className= rst.getString("className");
sBuf.append("<option value='"+classId+"'>"+className+"</option>\n");
}
}
catch (SQLException ex) {
return "";
}
return sBuf.toString();
}
//
public String getClassID(String className)
{
Statement stmt = null;
ResultSet rst = null;
StringBuffer sBuf=new StringBuffer();
try {
stmt=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
rst=stmt.executeQuery("select distinct classId from banji where className='"+className+"'");
while(rst.next()) {
String classId= rst.getString("classId");
sBuf.append("<option value='"+classId+"'>"+className+"</option>\n");
}
}
catch (SQLException ex) {
return "";
}
finally
{
try{
if (rst != null) {
rst.close();
}
if(stmt!=null){
stmt.close();
}
if(con!=null){
con.close();
}
}catch(Exception e)
{
e.printStackTrace();
}
}
return sBuf.toString();
}
//上传图象
public String uploadPhoto(String studentId,String photo)
{
PreparedStatement pstmt=null;
String str="";
try{
pstmt=con.prepareStatement("update xuesheng set photo=? where studentId=?");
pstmt.setString(1,photo);
pstmt.setString(2,studentId);
pstmt.execute();
str="sucess";//上传成功
}
catch(SQLException ex)
{
System.err.println(ex.getMessage());
str="failer";//上传失败
}
finally
{
try{
if(pstmt!=null){
pstmt.close();
}
if(con!=null){
con.close();
}
}catch(Exception e)
{
e.printStackTrace();
}
}
return str;
}
//上传图象
public int uploadImage(String studentId,String image)
{
Statement stmt=null;
int count=0;
try{
stmt=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
count=stmt.executeUpdate("update xuesheng set image='"+image+"' where studentId='"+studentId+"'");
}catch(SQLException ex)
{
System.err.println(ex.getMessage());
count=2;//失败
}
finally
{
try{
if(stmt!=null){
stmt.close();
}
if(con!=null){
con.close();
}
}catch(Exception e)
{
e.printStackTrace();
}
}
return count;
}
//获取图象
public String getPhoto(String studentId)
{
Statement stmt = null;
ResultSet rst = null;
String photo="";
try {
stmt=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
rst=stmt.executeQuery("select photo from xuesheng where studentId='"+studentId+"'");
if(rst.next()) {
photo= rst.getString("photo");
}
}
catch (SQLException ex) {
photo="";
}
finally
{
try{
if (rst != null) {
rst.close();
}
if(stmt!=null){
stmt.close();
}
if(con!=null){
con.close();
}
}catch(Exception e)
{
e.printStackTrace();
}
}
return photo;
}
/*
public static void main(String[] args)throws SQLException {
XueshengBean test=new XueshengBean();
ResultSet rst=test.getInfo("select * from v_xuesheng where studentId='0368110051'");
rst.next();
System.out.println(rst.getString(1));
} */
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -