3 Replies Latest reply: Sep 26, 2008 3:08 PM by 843785 RSS

    problem of  Mysql connection eclipse

    843785
      package CTest;

      import java.sql.DriverManager;
      import java.sql.SQLException;

      import javax.swing.JOptionPane;

      import com.mysql.jdbc.ResultSet;
      import com.mysql.jdbc.Statement;

      public class CTest {

           /**
           * @param args
           * @throws ClassNotFoundException
           * @throws SQLException
           */
           public static void main(String[] args) throws ClassNotFoundException, SQLException {
                // TODO Auto-generated method stub
                //Chargement de Driver
                Class.forName("com.mysql.jdbc.Driver");
                
                //Etablissement de la connection
                java.sql.Connection c = DriverManager.getConnection("jdbc:mysql://localhost/bd2","root","root" );
                
                //Cration de la zone de description de requte
                java.sql.Statement stmt = (Statement) c.createStatement();
                
                String s =JOptionPane.showInputDialog("veuillez entrer votre code DAB");
                java.sql.ResultSet rs= (ResultSet) stmt.executeQuery("select client.Code,Nom,Prenom,Solde,Numero"+"from client,compte where client.Code="+s+"AND client.Code=compte.Code");
                
                if(!rs.next())
                     JOptionPane.showInputDialog(null,"code DAB incorrect","erreur",JOptionPane.WARNING_MESSAGE);
                else
                { String s2=JOptionPane.showInputDialog("numero de compte: "+rs.getString("Numero")+
                                                                                           "\n Nom"+rs.getString("Nom")+
                                                                                           "\n prenom"+rs.getString("Prenom")+
                                                                                           "\n solde"+rs.getString("Solde"));
                
                String s3 =JOptionPane.showInputDialog("veuillez entrer le montant");
                
                float solde=rs.getFloat("Solde");
                float montant=Float.parseFloat("s3");
                
                if(montant>solde)
                     JOptionPane.showInputDialog(null,"votre solde est insuffisant","erreur",JOptionPane.WARNING_MESSAGE);
                else
                {float reste =solde-montant;
                stmt.executeUpdate("update compte set Solde ="+reste+" where Code="+s+"");
                JOptionPane.showInputDialog(null,"votre solde est:"+reste,"reste",JOptionPane.INFORMATION_MESSAGE);
                }
                }
                     
                
                }
                
      }

      the consol send me this:

      Exception in thread "main" com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'where client.Code=06358457AND client.Code=compte.Code' at line 1
           at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:936)
           at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2941)
           at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1623)
           at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1715)
           at com.mysql.jdbc.Connection.execSQL(Connection.java:3243)
           at com.mysql.jdbc.Connection.execSQL(Connection.java:3172)
           at com.mysql.jdbc.Statement.executeQuery(Statement.java:1197)
           at CTest.CTest.main(CTest.java:30)