private LoginActionForm getUserInfo(String userName,String userPassword,String sessionid)throws SQLException {
    LoginActionForm  myform=null;
       Connection conn=null;
       Statement stmt=null;
       Statement stmt1=null;
       ResultSet rs=null;
       ResultSet rs1=null;
       String sql="SELECT * FROM USERPURVIEW WHERE USERNAME='"+userName+"' and USERPASSWORD='"+userPassword+"'";       System.out.println(sql);
       BaseDAO dao=new BaseDAO();
       try{
         dao.Open();
         conn=dao.getConnection();
         stmt=conn.createStatement();
         rs=stmt.executeQuery(sql);    //运行到此步时程序自动跳到System.out.println("connection is error");行
         if(rs!=null){
         while(rs.next()){
       。
。。内容省略
       }catch(SQLException e){
         System.out.println("connection is error");
         throw new SQLException(e.getMessage());
       }finally{
       dao.CloseCon();
       }
       return  myform;
 }是哪里出错了?

解决方案 »

  1.   

    你就不能把SQLException 打印出来看看么。。
      

  2.   

    }catch(SQLException e){ 
            System.out.println("connection is error"); 
            e.printStackTrece()        throw new SQLException(e.getMessage()); 
          }finally{ 
          dao.CloseCon(); 
          } 
      

  3.   

    package java.sql;
    public class SQLException extends java.lang.Exception {  
        public SQLException(String reason, String SQLState, int vendorCode) {
    super(reason);
    this.SQLState = SQLState;
    this.vendorCode = vendorCode;
    if (!(this instanceof SQLWarning)) {
        if (DriverManager.getLogWriter() != null) {
    DriverManager.println("SQLException: SQLState(" + SQLState + 
    ") vendor code(" + vendorCode + ")");
    printStackTrace(DriverManager.getLogWriter());
        }
    }
        }    public SQLException(String reason, String SQLState) {
    super(reason);
    this.SQLState = SQLState;
    this.vendorCode = 0;
    if (!(this instanceof SQLWarning)) {
        if (DriverManager.getLogWriter() != null) {
    printStackTrace(DriverManager.getLogWriter());
    DriverManager.println("SQLException: SQLState(" + SQLState + ")");
        }
    }
        } 
        public SQLException(String reason) {
    super(reason);
    this.SQLState = null;
    this.vendorCode = 0;
    if (!(this instanceof SQLWarning)) {
        if (DriverManager.getLogWriter() != null) {
    printStackTrace(DriverManager.getLogWriter());
        }
    }
        }   
        public SQLException() {
    super();
    this.SQLState = null;
    this.vendorCode = 0;
    if (!(this instanceof SQLWarning)) {
        if (DriverManager.getLogWriter() != null) {
    printStackTrace(DriverManager.getLogWriter());
        }
    }
        }
        public String getSQLState() {
    return (SQLState);
        }
        public int getErrorCode() {
    return (vendorCode);
        }   
        public SQLException getNextException() {
    return (next);
        }
        public synchronized void setNextException(SQLException ex) {
    SQLException theEnd = this;
    while (theEnd.next != null) {
        theEnd = theEnd.next;
    }
    theEnd.next = ex;
        }
        private String SQLState;
        private int vendorCode;
        private SQLException next;
    }
      

  4.   

    SELECT * FROM USERPURVIEW WHERE USERNAME='1' and USERPASSWORD='1'connection is error
      

  5.   

    这是个登陆界面,sql语句是查询用户名密码 信息台就提示这么多
      

  6.   

    我希望在catch(SQLException e){ 
            System.out.println(e.getMessage()); 
    }这样输入你的异常看看。
      

  7.   

    catch(SQLException e){ 
            System.out.println("connection is error"); 
            e.printStackTrece()       
          }finally{ 
          dao.CloseCon(); 
          } 
    这样也行。。
      

  8.   

    把 conn 打印出来,连接上数据库了吗?
      

  9.   

    会不会连接没连接上??
    conn=dao.getConnection();你确定这个能连接上?