java.sql.SQLException: 調用中無效的參數這個錯誤是在結果集循環取出是拋出的。我不明白的是,用連接池才會拋出這個錯,用其它的連接就不會?在Weblogic中測試連接池也沒有問題。請問這是為什么?代碼在下面:
          public boolean isLogin(String uid, String pwd) {
              boolean isLogin = false;
              Connection conn = this.getConnection();
              if (conn != null) {
                String sql =
                    "select username,pwd from wasuserinfor where userName=? and pwd=?";
                try {
                  PreparedStatement ps = conn.prepareStatement(sql);
                  ps.setString(1, uid);
                  ps.setString(2, pwd);
                  ResultSet rs = ps.getResultSet();
                  while (rs.next()) {
                    String userNaem = rs.getString("USERNAME");
                    String password = rs.getString("PWD");
                    isLogin = true;
                  }
                }
                catch (SQLException ex) {
                  ex.printStackTrace();
                }
                finally {
                  if (conn != null) {
                    try {
                      conn.close();
                    }
                    catch (SQLException ex1) {
                      ex1.printStackTrace();
                    }
                  }
                }
              }
              return isLogin;
            }

            private Connection getConnection() {
              Object obj = null;
              try {
                Context ctx = new InitialContext();
                DataSource ds = (DataSource) ctx.lookup("jdbc/oracle");
                return ds.getConnection();
              }
              catch (SQLException ex) {
                return null;
              }
              catch (NamingException ex) {
                return null;
              }
            }
          解決辦法是看了代碼:ResultSet rs = ps.getResultSet();
          之前一個要先執行ps.executeQuery();這樣就不會有錯了。

          posted on 2005-12-23 14:31 rodney 閱讀(435) 評論(0)  編輯  收藏 所屬分類: 工作中遇到的問題與解決方式
           
          主站蜘蛛池模板: 五大连池市| 松原市| 革吉县| 奇台县| 鹤峰县| 临沂市| 勃利县| 亚东县| 砀山县| 盐亭县| 丰宁| 石台县| 石门县| 汝城县| 万源市| 荥经县| 郁南县| 宜黄县| 涟水县| 呼图壁县| 静海县| 林西县| 怀集县| 克东县| 斗六市| 红河县| 张家港市| 香港 | 靖安县| 涟水县| 大化| 平武县| 客服| 萨迦县| 太仆寺旗| 瑞安市| 揭西县| 临潭县| 延寿县| 永城市| 麻城市|