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.
- */
- import java.sql.*;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import javax.swing.*;
- import javax.swing.table.*;
- /**
- *
- * @author Muh Farid Zia
- */
- public class Soal3 extends javax.swing.JFrame {
- public Connection conn;
- public ResultSet rs;
- public PreparedStatement pst;
- /**
- * Creates new form Soal3
- */
- public Soal3() throws SQLException {
- initComponents();
- conn = null;
- conn = DriverManager.getConnection("jdbc:mysql://localhost/soal","root","");
- UpdateTabel();
- setLocationRelativeTo(null);
- }
- private void UpdateTabel() {
- try {
- String sql = "SELECT m.nama, m.alamat, n.nilai FROM nilai n INNER JOIN mahasiswa m ON m.id_mahasiswa = n.id_mahasiswa";
- pst = conn.prepareStatement(sql);
- rs = pst.executeQuery();
- DefaultTableModel dtm = (DefaultTableModel) jTable1.getModel();
- dtm.setRowCount(0);
- String [] data = new String[6];
- int i = 1;
- while(rs.next()) {
- data[0] = rs.getString("Nama");
- data[1] = rs.getString("Alamat");
- data[2] = rs.getString("Nilai");
- dtm.addRow(data);
- i++;
- }
- }
- catch (Exception e) {
- JOptionPane.showMessageDialog(null, e);
- }
- }
- /**
- * 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() {
- jLabel1 = new javax.swing.JLabel();
- jScrollPane1 = new javax.swing.JScrollPane();
- jTable1 = new javax.swing.JTable();
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- jLabel1.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
- jLabel1.setText("Data Nilai Mahasiswa");
- jTable1.setModel(new javax.swing.table.DefaultTableModel(
- new Object [][] {
- {null, null, null},
- {null, null, null},
- {null, null, null},
- {null, null, null}
- },
- new String [] {
- "Nama", "Alamat", "Nilai"
- }
- ));
- jScrollPane1.setViewportView(jTable1);
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGap(124, 124, 124)
- .addComponent(jLabel1))
- .addGroup(layout.createSequentialGroup()
- .addContainerGap()
- .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 375, javax.swing.GroupLayout.PREFERRED_SIZE)))
- .addContainerGap(15, Short.MAX_VALUE))
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGap(21, 21, 21)
- .addComponent(jLabel1)
- .addGap(18, 18, 18)
- .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 275, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- );
- pack();
- }// </editor-fold>
- /**
- * @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(Soal3.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (InstantiationException ex) {
- java.util.logging.Logger.getLogger(Soal3.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (IllegalAccessException ex) {
- java.util.logging.Logger.getLogger(Soal3.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (javax.swing.UnsupportedLookAndFeelException ex) {
- java.util.logging.Logger.getLogger(Soal3.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() {
- try {
- new Soal3().setVisible(true);
- } catch (SQLException ex) {
- Logger.getLogger(Soal3.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- });
- }
- // Variables declaration - do not modify
- private javax.swing.JLabel jLabel1;
- private javax.swing.JScrollPane jScrollPane1;
- private javax.swing.JTable jTable1;
- // End of variables declaration
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement