如何在JLabel中显示来自MySQL的数据?

时间:2016-08-10 07:18:16

标签: java mysql swing jlabel

我如何从MySQL获得“目标”值到JLabel?我是否必须将其分成不同的功能?

Jlabel GOAL = new JLabel(""); 

    try {
        //connection to database
        Connection myConn = DriverManager.getConnection("jdbc:mysql://localhost:8889/Daily", "student", "student");

        Statement myStmt = myConn.createStatement();

        ResultSet rs = myStmt.executeQuery("select Goal from User WHERE id=1");

        GOAL.setText(rs.getString("Goal"));

    }
    catch (Exception e) {
        e.printStackTrace();
    }

    GOAL.setForeground(Color.LIGHT_GREEN);
    GOAL.setBounds(23, 90, 61, 45);
    contentPane.add(GOAL);
    `

0 个答案:

没有答案