Search code examples
javaswingjoptionpane

Simple JOptionPane.showMessage();


This is the code of a button that when is clicked it searches for a user id in a database and displays name, last name and hours. What I want to do is to pop up a message(JOptionPane.showMessage()) that shows the time when the user clocks in/out so what I thought I could do is to add "JOptionPane.showMessage()" to do exactly that, but when I put this code(no matter where) there is a red line under "showMessage" and an error message saying:

==cannot find symbol
==symbol: method showMessage(java.lang.String)
==location:class javax.swing.JOptionPane

Not sure what that means. Any help very much appreciated. Thank you.

private void clockInOutActionPerformed(java.awt.event.ActionEventevt){   

    // TODO add your handling code here:
    try{
stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,  ResultSet.CONCUR_UPDATABLE);
           String sql = "SELECT * FROM Students WHERE STUDENTID = ?";
        PreparedStatement pstmt = con.prepareStatement(sql);
        pstmt.setInt(1, Integer.parseInt(jTextField1.getText()));
        ResultSet rs = pstmt.executeQuery();

        if(rs.next()){
            String first = rs.getString(2);
            String last = rs.getString(3);
            String hours = rs.getString(6);

            fName.setText(first);
            lName.setText(last);
            tHours.setText(hours);
        }       
    }
    catch(SQLException err){
        JOptionPane.showMessageDialog(Student.this, err.getMessage());
    }
}

Solution

  • Probably you misspelled the class name or you didn't import the class name, check that and try again. And also what Andrew Said.

    In case you are using the IDE Eclipse if you press Ctrl+Shift+o (letter O) it imports everything automatically for you.

    Hope it helps.