useBean 调用类时,遇到错误 ,如何终止,并返回信息给用户!
package com;
import java.sql.*;
import db.*;
public class newManage
{
ConnDB con= new ConnDB();
private String userid,password,qy,username,bm,job,type;
public void setUserid(String u){userid=u;}
public String getUserid(){return userid;}
public void setPassword(String p){password=p;}
public String getPassword(){return password;}
public void setQy(String q){qy=q;}
public String getQy(){return qy;}
public void setUsername(String n){username=n;}
public String getUsername(){return username;}
public void setBm(String b){bm=b;}
public String getBm(){return bm;}
public void setJob(String j){job=j;}
public String getJob(){return job;}
public void setType(String t){type=t;}
public String getType(){return type;}
/***********************************************************************
*函 数 名:updateDatabase
*功能描述:添加管理员帐号
***********************************************************************/
public void updateDatabase(){
// 定义链接的conn对象
Connection conn=null;
try {
// 打开数据库连接
conn=con.mygetConn();
// 数据判断
if (userid!=null)
userid = new String(userid.getBytes( "ISO-8859-1 "), "GBK ");
else
userid= "未知 ";
if (qy!=null)
qy = new String(qy.getBytes( "ISO-8859-1 "), "GBK ");
else
qy= "未知 ";
if (job!=null)
job = new String(job.getBytes( "ISO-8859-1 "), "GBK ");
else
job= "未知 ";
if (bm!=null)
bm = new String(bm.getBytes( "ISO-8859-1 "), "GBK ");
else
bm= "未知 ";
if (username!=null)
username = new String(username.getBytes( "ISO-8859-1 "), "GBK ");
else
username= "未知 ";
if ( "1 ".equals(type)){}else{type= "0 ";}
// 检查帐号是否重复
String clickSql= "Select userid From Manages Where userid=? ";
PreparedStatement perstmt=conn.prepareStatement(clickSql);;
perstmt.setString(1,userid);
ResultSet rs=perstmt.executeQuery();
if(rs.next()){
System.out.print( "对不起,帐号重复了! ");
}else{
//添加管理员信息
String sql= "Insert Into Manages(userid,[password],qy,username,job,bm,type) values(?,?,?,?,?,?,?) ";
perstmt=conn.prepareStatement(sql);
perstmt.setString(1,userid);
perstmt.setString(2,password);
perstmt.setString(3,qy);
perstmt.setString(4,username);
perstmt.setString(5,job);
perstmt.setString(6,bm);
perstmt.setString(7,type);
perstmt.executeUpdate();
System.out.print( "成功添加管理员信息! ");