我如何从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);
`