1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
|
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
} |
Partager