驱动程序不支持此功能

驱动程序不支持此功能

我正在酒店管理上做一个项目,该项目的GUI是使用Swings和SQl Server Management Studio,2008设计的,用于存储数据。但是我面临的问题是,由于“驱动程序不支持此功能”,我遇到了一个异常。 ..我无法解决此问题...请向我指出我要去的地方..在此先感谢.. :)

我已经创建了两种形式:SignUp表单和Login表单...这是我被困住的SignUp表单...

btnSubmit = new JButton("SUBMIT");
    btnSubmit.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
         try{
             if(textField.getText().equals("") || textField_2.getText().equals("") ||
             textField_5.getText().equals("") || textField_6.getText().equals("") ||
             textField_7.getText().equals("") || passwordField.getPassword().equals("")
             || passwordField_1.getPassword().equals("")){
                    JOptionPane.showMessageDialog(null,"Fields cannot be left
              empty!!!");
                }
             else{
                 Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                 Connection con=DriverManager.getConnection("jdbc:odbc:SignUp_DSN");
                 String firstname=textField.getText();
                 String lastname=textField_1.getText();
                 String email_id=textField_2.getText();
                 String country=textField_5.getText();
                 String state=textField_6.getText();
                 String ph_no=textField_7.getText();
                 char[] password=passwordField.getPassword();
                 char[] retype_password=passwordField_1.getPassword();

            if(!password.equals(retype_password)){
                     JOptionPane.showMessageDialog(null,"Passwords are not
                     matching.Enter again!!!"); }


                if(password.length<8 || retype_password.length<8){
                     JOptionPane.showMessageDialog(null,"Password should be more than 8
                     characters!!!");
                }
            String sql="insert into  Sign_Up(`Firstname`,`Lastname`,`Email_id`,`Password`,`Retype_Password`,`Country`,`State`,`Phone_no`) values(?,?,?,?,?,?,?,?)";
                  PreparedStatement ps=con.prepareStatement(sql);
                     ps.setString(1, firstname);
                     ps.setString(2, lastname);
                     ps.setString(3, email_id);
                     ps.setString(6, country);
                     ps.setString(7, state);
                     ps.setString(8,ph_no);
                     ps.setString(4, new String(password));
                     ps.setString(5, new String(retype_password) );
                     ResultSet rs=ps.executeQuery(sql);
                      while(rs.next()){ }
                con.close();
                    ps.close();
                    //rs.close();
                 }
    }catch(Exception ex){

                    String str=ex.toString();
                    JOptionPane.showMessageDialog(null,str);
            }
        }
});


而且密码匹配的条件不起作用...我收到一条对话消息,提示密码并不总是匹配;密码是否匹配!!!

最佳答案

我想我看到了问题,

PreparedStatement ps=con.prepareStatement(sql);
ps.setString(1, firstname);
ps.setString(2, lastname);
ps.setString(3, email_id);
ps.setString(6, country);
ps.setString(7, state);
ps.setString(8,ph_no);
ps.setString(4, new String(password));
ps.setString(5, new String(retype_password) );
ResultSet rs=ps.executeQuery(sql); // <-- here.


您设置了PreparedStatement查询并绑定了参数,但是当您将String sql传递给executeQuery()时,您将再次调用未绑定查询!

ResultSet rs=ps.executeQuery();


另外,您应该添加一个finally块以关闭rsps

关于java - java.sql.SQLException:“驱动程序不支持此功能”,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24818307/

10-10 04:17