2

I am doing a project on Hotel Management whose GUI is being designed using Swings and SQl Server Management Studio,2008 to store the data.But the problem I am facing is,i am getting an exception as "Driver does not support this function"...I am not able to sort out this problem...kindly enlighten me where I am going wrong..Thanks in advance..:)

I have created 2 forms:SignUp form and Login form...Here is my SignUp form where I am stuck...

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);
            }
        }
});

And also the condition for Password matching is not working...I get a Dialogue message saying passwords doesn't match always;whether the password match or not!!!

1
  • 3
    Unrelated but: don't use the JDBC/ODBC bridge. It has always been buggy and slow and it is no longer available in Java 8. Use a real JDBC driver instead. Commented Jul 18, 2014 at 6:36

4 Answers 4

4

I think I see the problem,

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.

You set-up your PreparedStatement query and bind the parameters, but then you call the unbound query again when you pass String sql to executeQuery()!

ResultSet rs=ps.executeQuery();

Also, you should add a finally block to close rs and ps.

Sign up to request clarification or add additional context in comments.

5 Comments

I l try..and get back in a min..thnx.
@user3801050 Move the variable conn, rs and ps variable declarations outside the try block (declare as null and assign in the try, or use the new try with resources).
Exception is gone...but the data is not getting stored in the database when I input in the GUI form..Can anybdy suggest me where I am going wrng!!! :(
I did exactly as u said...still not working..:( nothing is getting stored in database..!!!
Post another question with the query, your exception sounds resolved. Are you getting a new exception? This was a select, where is the insert?
2

Your column name 'state' is a keyword. Rename the column to something else.

Comments

0

There are two questions in your one question:

  1. Why isn't the password check working? It's because you can't compare two char-Arrays using equals. Arrays don't override equals(), so it is basically a ==-check. Use Arrays.equals(password, retype_password)
  2. As Elliott said: you are already setting your sql-query in the prepareStatement - don't pass it again in executeQuery()

There are some other issues I want to point out:

  • There's no need to store password and retype_password - they are equal anyway.
  • NEVER STORE PASSWORDS IN CLEARTEXT. Always use a suitable hash-function with salt like PBKDF2

1 Comment

thanx for the info..I l come back after trying this..:)
0

The error is parameters not compatible.

The executeQuery function in PreparedStatement is executeQuery() without parameters

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.