dimanche 24 avril 2016

How can I make my program display the user's name from the database in JtextField?

I'm making a program where you login and it takes you into a into a different frame after you log in.. That part of the program works, but I'm having trouble getting it to return the user's name and other data from the database. It connects to the database, but it won't return the information inside JTextField. If I can find out how to do firstName, I can figure out the rest. I'm using Eclipse as my IDE and SQLite Manager as the database. There are 2 tables Login (username,password) Student(SID,firstName,GradeLevel, and more) Also username is there ID start with an S (like S01 and so forth). Here's the code.

public class student extends JFrame {
private JTextField textField;

public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {
        public void run() {
            try {
                student frame = new student();
                frame.setVisible(true);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}
private void ShowInfo() {

try{


    String query="SELECT firstName From Student,Login Where firstname=?";
    PreparedStatement ps=conn.prepareStatement(query);
    ps.setString(1, "firstName");
    ResultSet rs= ps.executeQuery();
    while (rs.next()) {
    textField.setText(rs.getString("firstName"));
        System.out.print(""+textField);
    }ps.close();
    conn.close();
    } catch ( Exception ex)
    {

        JOptionPane.showMessageDialog(null,ex);
}


}

}

Aucun commentaire:

Enregistrer un commentaire