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 . Buts when I print the stack trace trace its telling me the table does not exist.

First check if the connection is being made correctly. Check if con is null. If yes it means connection is not getting established in the first place, check if you have set driver path correctly

what you also could do .... tell us:
1. what is the desired output
2. what is your actual output
3. is the code running or crashing?
4. do you get any error messages?
...

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 . Buts when I print the stack trace trace its telling me the table does not exist.

Post the full error messages here(including line number), because then we can help tell you exactly what might be going wrong and where...

catch (Exception e)
{
  JOptionPane.showMessageDialog(...Cannot connect you to the database.
}

Actually there are many other Exceptions that could be thrown from your try block eg null pointer... who knows? But this code will make you think it's always a database connection problem
When developing your code you should ALWAYS do a full e.printStackTrace(); in every catch block until you are certain exactly what's happening.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.