因此,当我单击另一个“show hint”标签时,查询语句本身将被打印到jLabel中而不是将查询结果打印到Jlabel中
private void jLabel7MouseClicked(java.awt.event.MouseEvent evt) {
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection CC = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/pulsedb", "root", "passtheword");
String query = "SELECT hint FROM mstufflogin WHERE username = 'tapiwa'";
PreparedStatement PS = CC.prepareStatement(query);
PS.executeQuery(query);
jLabel6.setText("HINT: " + query);
}
标签上的输出将是.... SELECT hint FROM mstufflogin WHERE username = 'tapiwa'
答案 0 :(得分:1)
将查询替换为查询结果
ResultSet result = PS.executeQuery();
result.next();
jLabel6.setText("HINT: " + result.getString(1));
答案 1 :(得分:-1)
我认为你选错了变量(查询)?
尝试
jLabel6.setText("Hint:"+PS.getString("HINT"));