Jump to content

How Do I Take Just 1 Value From Database And Put It In A Label?


iNko

Recommended Posts

Hey, i need to take just one element from my database table. I have this table - Users. and it has ID, Login, Password and Surname. I want to take just surname from this table. Something like ("Select Surname from Users where login =")

 

Im trying to use this, but it gives me errors saying this ("Unkown column 'Admin' in 'where clause'"):

private void whoslogedinLabel(){
   String sql = "select Surname from Users where login = Admin";
try {
	pst = conn.prepareStatement(sql);
	rs = pst.executeQuery();
       logininfoLabel.setText(sql);
}
catch (Exception e){
	JOptionPane.showMessageDialog(null, e);
}
}

logininfoLabel - is the label where i want the Surname to be displayed

made it work:


private void whoslogedinLabel(){

   try {
       String sql = "SELECT vardas_pavarde FROM Vartotojas WHERE login='" + whosloggedin + "'"; 
      pst = conn.prepareStatement(sql);
      //pst.setString(1, whosloggedin);      
      rs = pst.executeQuery(sql);
      while (rs.next())
      {
          logininfoLabel.setText(rs.getString("vardas_pavarde"));   
      }

}
   catch (Exception e){
       JOptionPane.showMessageDialog(null, e);
   } 
   }

thx guys

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.