Jump to content

Code not giving desired output

- - - - -

  • Please log in to reply
5 replies to this topic

#1
hbk

hbk

    Learning Programmer

  • Members
  • PipPipPip
  • 71 posts

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {

        // TODO add your handling code here:

        String sql="Select BADGE_NUMBER,FIRST_NAME from POLICE_TABLE";

        

        try 

        {

            Class.forName("org.apache.derby.jdbc.ClientDriver").newInstance();           

            Connection con= (Connection) DriverManager.getConnection("jdbc:derby://localhost:1527/Traffic Ticket System","Administrator","admin1234");

            /*As we are creating a connection on a local computer we will write the url as jdbc:mysql://localhost:3306 */

            

            Statement stmt=con.createStatement();

            ResultSet rs = stmt.executeQuery(sql);

            

            String user=jTextField1.getText();

            String pwd= new String (jPasswordField1.getPassword());

            

            while(rs.next())

            {   

                

                String uname=rs.getString("FIRST_NAME");

                //Username is the coloumn name in the database table 

                String password=rs.getString("BADGE_NUMBER");

                


                if ((user.equals(uname)) && (pwd.equals(password)))

                {

                    JOptionPane.showMessageDialog(null, "Welcome to the system " + uname);

                    JFrame frame = new JFrame();

                    frame.setContentPane(new Offender_Form());

                    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

                    frame.setTitle("Traffic Ticket System Offender Menu");

                    frame.setExtendedState(JFrame.MAXIMIZED_BOTH);

                    frame.pack();

                    frame.setVisible(true);

                }

            }

        }

        catch (Exception e)

        {

            JOptionPane.showMessageDialog(null,"Cannot connect you to the database. Make sure your entering the correct First Name and Badge Number. "

                    + "Please try again.");

        }

        

    }



My Table columns are set up like:


BADGE_NUMBER, DIVISION, TITLE, FIRST_NAME............



I have the following code above. I am trying to use data from my table to verify login into the database but its always throwing the exception. The code does compile without error.

#2
Norm

Norm

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 327 posts

Quote

its always throwing the exception.
Please post the full text of the error message.

Be sure to call the printStackTrace() method in the catch block so you get the full text of the error message.

#3
hbk

hbk

    Learning Programmer

  • Members
  • PipPipPip
  • 71 posts

Norm said:

Please post the full text of the error message.

Be sure to call the printStackTrace() method in the catch block so you get the full text of the error message.

Its telling me that the table does not exist but it does.

#4
Norm

Norm

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 327 posts
Sorry, without the full text of the error message I have no idea what the problem is.

#5
chili5

chili5

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 7,247 posts
  • Programming Language:Java, C#, PHP
  • Learning:C, C++, C#, PHP, Transact-SQL, Assembly, Scheme

Quote

Its telling me that the table does not exist but it does.

Based on this I'm thinking you have the database information wrong. Check that the information is correct. If not, what does the stack trace say? Can you post it?

Is it possible that it is messing up because of spaces in the database name?

#6
hbk

hbk

    Learning Programmer

  • Members
  • PipPipPip
  • 71 posts

Norm said:

Sorry, without the full text of the error message I have no idea what the problem is.

Thanks for the feedback. I figured it out.

I should have placed the appropriate schema before the table name.

So the fix is:
String sql="Select BADGE_NUMBER,FIRST_NAME from APP.POLICE_TABLE";




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users