• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Connection of user in Jframe Netbeans

 
nadia ghezaiel
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I create a JFrame for this connection of user (authentification).My connection to Sql server via NetBeans is estableshed!!but infortunaly I don't know what's the matter in this code::

public void seConnecter(String Nom,String Adresse)
{
String requete = "SELECT Nom FROM Authentif.dbo.tab_authentif where Adresse ="+Adresse;

try {
Statement st = C.createStatement();
ResultSet resultat = st.executeQuery(requete);
while(resultat.next())
{

if(Adresse.equals(resultat.getString("Adresse"))==0)
{
JOptionPane.showMessageDialog(null,"Connexion reuissi!!");
}
else
{
JOptionPane.showMessageDialog(null,"Veuillez vérifier vos coordonnées!!");
}


catch (SQLException ex)
{
System.out.println("Erreur lors de la recherche de l'utilisateur.");
ex.printStackTrace();
JOptionPane.showMessageDialog(null,ex.getMessage());
}
}

Please help me!!!
 
Swastik Dey
Rancher
Posts: 1643
6
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What problem are you facing? Please paste your code inside code tags.
 
nadia ghezaiel
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thinks Swastik!!My prob is solved!!!the error was "if(Adresse.equals(Adr)==0)" it should be if(Adresse.equals(Adr))!!!
Thinks
 
nadia ghezaiel
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But now i have another one!!!
When i run my pgm:::I find this message "Incorrect syntax near '='."
I don't inderstand what it means???A bout Sql statement or what??
 
Swastik Dey
Rancher
Posts: 1643
6
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your query syntax is wrong. Moreover do you actually need that if check?

Try the following code

 
nadia ghezaiel
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think we should use executeQuery("SELECT Nom FROM Authentif.dbo.tab_authentif where Adresse=?") not "prepareStatement(requete)" because we need to select from the table not to isert!!!
 
Swastik Dey
Rancher
Posts: 1643
6
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Who told you that PreparedStatement is used for insertion of record? Your code is highly sensitive to sql injection. Look into/Study about PreparedStatement and you will get a better idea about that.
 
Swastik Dey
Rancher
Posts: 1643
6
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You may wish to refer to this

http://docs.oracle.com/javase/7/docs/api/java/sql/PreparedStatement.html#executeQuery()
 
nadia ghezaiel
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thinks!!!it's good know,!!!you are sooooooo nice!!!thinks
 
Swastik Dey
Rancher
Posts: 1643
6
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are welcome.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic