bonjour à tous,je suis sur un projet de gestion bancaire,j'ai crée un Jframe Position pour rechercher en fonction du numero de compte les valeurs correspondante dans la table Compte et les afficher dans les champs correspondants de mon Jframe,seulement je suis confronté à un problème de requete,aidez moi à trouver ou se situe le probleme,voici mon code :
private void rechercherActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String user = "root";
String password = "pytheas";
ResultSet rs = null;
Statement st = null;
Connection con=null;
try{
Class.forName("com.mysql.jdbc.Driver");
String url="jdbc.mysql://localhost:3306/banque";
con=(Connection) DriverManager.getConnection(url, user, password);
st=con.createStatement();
String rq="select NomClt,PrenomClt,SoldeCpt from Compte where NumCpte='" + numcptposition.getText() + "'";/*NomClt,PrenomClt et SoldeCpt sont les champs de la table Compte,numcptposition correspond au champ duJframe ou pourrait se situé l'erreur*/
rs = st.executeQuery(rq);
String numcompte="";
String nomposition="";
String prenomposition="";
String montant;
float soldeposition;
while(rs.next())
{
numcompte = rs.getString("NumCpte");
nomposition = rs.getString("NomClt");
prenomposition = rs.getString("PrenomClt");
soldeposition = rs.getFloat("SoldeCpt"); /*je veus récupérer le solde qui est du type float*/
//montant=resultats.getString("SoldeCpt");
// soldeposition= = Float.parseFloat(montant);
}
numcptposition.setText(numcompte);
nomrsposition.setText(nomposition);
prenomrsposition.setText(prenomposition);
// montantposition.setText(soldeposition);/*afficher le solde dans le champs correspondant dans le Jframe mais il signale erreur*/
}catch(ClassNotFoundException e)
{
JOptionPane.showMessageDialog(null,"Mauvais Driver","Erreur",JOptionPane.ERROR_MESSAGE);
}catch(SQLException sq)
{
JOptionPane.showMessageDialog(null,"Erreur de la requête","Erreur",JOptionPane.ERROR_MESSAGE);
}
finally
{
if(st == null)
{
try
{
st.close();
}catch(SQLException e)
{
e.printStackTrace();
}
}
if(con!=null)
{
try
{
con.close();
}catch(SQLException e1)
{
e1.printStackTrace();
}
}
}
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Position().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JTextField montantposition;
private javax.swing.JTextField nomrsposition;
private javax.swing.JTextField numcptposition;
private javax.swing.JTextField prenomrsposition;
private javax.swing.JButton rechercher;
// End of variables declaration
}