• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Connection of user in Jframe Netbeans

 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!!!
 
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thinks!!!it's good know,!!!you are sooooooo nice!!!thinks
 
Swastik Dey
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are welcome.
 
Won't you be my neighbor? - Fred Rogers. tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic