Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.