package base;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.Statement;
/**
*
* @author pcfutur
*/
public class bdd extends javax.swing.JFrame {
/** Creates new form NewJFrame */
public bdd() {
initComponents();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jButton1 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jButton1.setText("afficher facture");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(159, 159, 159)
.addComponent(jButton1)
.addContainerGap(134, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(104, 104, 104)
.addComponent(jButton1)
.addContainerGap(173, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String titre="La recherche des facture nom payer :";
String message="les factures recherchés sont :";
try {
Class.forName("org.postgresql.Driver");
String url = "jdbc:postgresql://localhost:5432/sonelgaz";
String user = "postgres";
String passwd = "**********";
Connection conn = DriverManager.getConnection(url, user, passwd);
//Création d'un objet Statement
Statement state = conn.createStatement();
ResultSet result = state.executeQuery("SELECT * FROM facture WHERE facture.etat='En Instance' ");
ResultSetMetaData resultMeta = result.getMetaData();
while(result.next()){
message+="\n";
message+="\t" +resultMeta.getColumnName(1).toUpperCase() +": "+result.getObject(1).toString()+ "\t ";
message+="\n";
message+="\t" +resultMeta.getColumnName(2).toUpperCase() +": "+result.getObject(2).toString()+ "\t ";
message+="\n";
message+="\t" +resultMeta.getColumnName(3).toUpperCase() +": "+result.getObject(3).toString()+ "\t ";
message+="\n";
message+="\t" +resultMeta.getColumnName(8).toUpperCase() +": "+result.getObject(8).toString()+ "\t ";
message+="\n";
message+="__________________________________________________________";
message+="\n";}
result.close();
state.close();
}catch (Exception e) {
e.printStackTrace();
}
javax.swing.JOptionPane.showMessageDialog(this,message,titre,javax.swing.JOptionPane.INFORMATION_MESSAGE);
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see
http://download.oracle.com/javase/tu...feel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(bdd.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(bdd.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(bdd.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(bdd.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new bdd().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
// End of variables declaration
}
Partager