java.sql.SQLException:“驱动程序不支持此功能”

时间:2014-07-18 06:12:14

标签: java sql jdbc-odbc

我正在做一个关于酒店管理的项目,其GUI正在使用Swings和SQl Server Management Studio,2008设计来存储数据。但是我遇到的问题是,我得到一个例外,因为“驱动程序不支持这个功能“...我无法解决这个问题...请告诉我我哪里出错了...谢谢提前......:)

我创建了2个表单:SignUp表单和登录表单...这是我的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);
            }
        }
});

密码匹配的条件也不起作用......我收到一条Dialogue消息,说密码总是不匹配;密码是否匹配!!!

4 个答案:

答案 0 :(得分:4)

我想我看到了问题,

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

答案 1 :(得分:2)

您的专栏名称&#39;州&#39;是一个关键字。将列重命名为其他内容。

答案 2 :(得分:0)

您的一个问题有两个问题:

  1. 为什么密码检查不起作用?这是因为您无法使用char比较两个equals - 数组。数组不会覆盖equals(),因此它基本上是== - 检查。使用Arrays.equals(password, retype_password)
  2. 正如Elliott所说:您已经在prepareStatement中设置了SQL查询 - 请勿在{{1​​}}中再次传递
  3. 我还想指出一些其他问题:

    • 无需存储executeQuery()password - 无论如何它们都是平等的。
    • 从不在CLEARTEXT中存储密码。始终使用合适的哈希函数与盐,如PBKDF2

答案 3 :(得分:0)

错误是参数不兼容。

PreparedStatement中的executeQuery函数是executeQuery(),没有参数

相关问题