Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package tp3.bdd.ex2a5;
- import java.sql.Connection;
- import java.sql.DatabaseMetaData;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import javax.swing.table.DefaultTableModel;
- /**
- *
- * @author kasprzykn
- */
- public class NewJFrame extends javax.swing.JFrame {
- /**
- * Creates new form NewJFrame
- */
- public NewJFrame() {
- initComponents();
- }
- private Connection conn;
- private Statement stmt;
- private DatabaseMetaData meta;
- private String pass;
- /**
- * 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">//GEN-BEGIN:initComponents
- private void initComponents() {
- jLabel1 = new javax.swing.JLabel();
- jLabel2 = new javax.swing.JLabel();
- login = new javax.swing.JTextField();
- jButton1 = new javax.swing.JButton();
- liste = new javax.swing.JComboBox();
- jScrollPane1 = new javax.swing.JScrollPane();
- table = new javax.swing.JTable();
- pwd = new javax.swing.JPasswordField();
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- jLabel1.setText("Login");
- jLabel2.setText("Password");
- login.setText("IQ_BD_");
- login.setName("login"); // NOI18N
- jButton1.setText("OK");
- jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
- public void mouseClicked(java.awt.event.MouseEvent evt) {
- jButton1MouseClicked(evt);
- }
- });
- liste.setEnabled(false);
- liste.addMouseListener(new java.awt.event.MouseAdapter() {
- public void mouseClicked(java.awt.event.MouseEvent evt) {
- listeMouseClicked(evt);
- }
- });
- liste.addItemListener(new java.awt.event.ItemListener() {
- public void itemStateChanged(java.awt.event.ItemEvent evt) {
- listeItemStateChanged(evt);
- }
- });
- table.setModel(new javax.swing.table.DefaultTableModel(
- new Object [][] {
- },
- new String [] {
- "Colonne", "Type"
- }
- ) {
- boolean[] canEdit = new boolean [] {
- false, false
- };
- public boolean isCellEditable(int rowIndex, int columnIndex) {
- return canEdit [columnIndex];
- }
- });
- jScrollPane1.setViewportView(table);
- 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(35, 35, 35)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
- .addComponent(jButton1, javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jLabel1)
- .addComponent(jLabel2))
- .addGap(26, 26, 26)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
- .addComponent(login, javax.swing.GroupLayout.DEFAULT_SIZE, 70, Short.MAX_VALUE)
- .addComponent(pwd))))
- .addGap(33, 33, 33)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGap(235, 235, 235)
- .addComponent(liste, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGroup(layout.createSequentialGroup()
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 324, javax.swing.GroupLayout.PREFERRED_SIZE)))
- .addContainerGap())
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGap(83, 83, 83)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jLabel1)
- .addComponent(login, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(liste, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGap(31, 31, 31)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jLabel2)
- .addComponent(pwd, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGap(18, 18, 18)
- .addComponent(jButton1))
- .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 243, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addContainerGap(30, Short.MAX_VALUE))
- );
- pack();
- }// </editor-fold>//GEN-END:initComponents
- private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton1MouseClicked
- try{
- DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
- pass=new String(pwd.getPassword());
- conn = DriverManager.getConnection("jdbc:oracle:thin:@srv-iq-bdd:1521:iqbd", login.getText(), pass);
- stmt = conn.createStatement();
- String query = "SELECT table_name FROM user_tables";
- ResultSet rset = stmt.executeQuery (query);
- String str;
- liste.setEnabled(true);
- while (rset.next())
- {
- str = rset.getString(1);
- liste.addItem(str);
- }
- rset.close();
- }
- catch(SQLException e){
- System.out.println("ERR : "+e.getErrorCode()+":"+e.getMessage());
- }
- }//GEN-LAST:event_jButton1MouseClicked
- private void listeItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_listeItemStateChanged
- try {
- meta = conn.getMetaData();
- ResultSet rsColonnes=meta.getColumns(null, null, liste.getSelectedItem()+"", null);
- DefaultTableModel model=(DefaultTableModel)table.getModel();
- if (model.getRowCount()>0){
- for (int i=0;i<model.getRowCount();i++){
- model.removeRow(i);
- }
- }
- table.setModel(model);
- while (rsColonnes.next()) {
- model.addRow(new Object[]{rsColonnes.getString("COLUMN_NAME"),rsColonnes.getString("TYPE_NAME")});
- }
- rsColonnes.close();
- } catch (SQLException e) {
- System.out.println("ERR : "+e.getErrorCode()+":"+e.getMessage());
- }
- }//GEN-LAST:event_listeItemStateChanged
- private void listeMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_listeMouseClicked
- }//GEN-LAST:event_listeMouseClicked
- /**
- * @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/tutorial/uiswing/lookandfeel/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(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (InstantiationException ex) {
- java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (IllegalAccessException ex) {
- java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (javax.swing.UnsupportedLookAndFeelException ex) {
- java.util.logging.Logger.getLogger(NewJFrame.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 NewJFrame().setVisible(true);
- }
- });
- }
- // Variables declaration - do not modify//GEN-BEGIN:variables
- private javax.swing.JButton jButton1;
- private javax.swing.JLabel jLabel1;
- private javax.swing.JLabel jLabel2;
- private javax.swing.JScrollPane jScrollPane1;
- private javax.swing.JComboBox liste;
- private javax.swing.JTextField login;
- private javax.swing.JPasswordField pwd;
- private javax.swing.JTable table;
- // End of variables declaration//GEN-END:variables
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement