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 latihan15;
- import javax.swing.SwingUtilities;
- import javax.swing.JTable;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.ResultSetMetaData;
- import java.sql.Statement;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import javax.swing.table.DefaultTableModel;
- import java.sql.*;
- import java.util.Locale;
- import java.util.Vector;
- import java.text.SimpleDateFormat;
- import java.util.Calendar;
- import com.toedter.calendar.JDateChooser;
- import java.text.DateFormat;
- /**
- *
- * @author steven
- */
- public class CariData9 extends javax.swing.JFrame {
- /**
- * Creates new form CariData9
- */
- public CariData9() {
- 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() {
- jDateChooser1 = new com.toedter.calendar.JDateChooser();
- jButton1 = new javax.swing.JButton();
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- jDateChooser1.setDateFormatString("EEEE, dd MMMM yyyy");
- jDateChooser1.setFont(new java.awt.Font("Cantarell", 1, 15)); // NOI18N
- jButton1.setFont(new java.awt.Font("Cantarell", 1, 15)); // NOI18N
- jButton1.setText("Cari");
- 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()
- .addContainerGap()
- .addComponent(jDateChooser1, javax.swing.GroupLayout.PREFERRED_SIZE, 260, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addContainerGap(248, Short.MAX_VALUE))
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addContainerGap()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
- .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(jDateChooser1, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addContainerGap(258, Short.MAX_VALUE))
- );
- pack();
- }// </editor-fold>
- private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- // java.sql.Date dataDate = new java.sql.Date(jDateChooser1.getDate().getTime());
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
- String dataDate = sdf.format(jDateChooser1.getDate().getTime());
- Connection koneksi = null;
- Statement stmt = null;
- String cariTanggal = "SELECT * FROM testdatapegawai1 WHERE tanggallahir = '" + dataDate + "'";
- String url = "jdbc:postgresql://localhost:5432/pdam";
- String user = "steven";
- String password = "kucing";
- try{
- koneksi = DriverManager.getConnection(url,user,password);
- stmt = koneksi.createStatement();
- ResultSet rs = stmt.executeQuery(cariTanggal);
- while(rs.next()){
- String nik = rs.getString("nik");
- String namalengkap = rs.getString("namalengkap");
- String jeniskelamin = rs.getString("jeniskelamin");
- System.out.println(nik + "\t" + namalengkap + "\t" + jeniskelamin);
- }
- //koneksi.close();
- } catch(SQLException ex){
- ex.printStackTrace();
- }
- }
- /**
- * @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(CariData9.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (InstantiationException ex) {
- java.util.logging.Logger.getLogger(CariData9.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (IllegalAccessException ex) {
- java.util.logging.Logger.getLogger(CariData9.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (javax.swing.UnsupportedLookAndFeelException ex) {
- java.util.logging.Logger.getLogger(CariData9.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 CariData9().setVisible(true);
- }
- });
- }
- // Variables declaration - do not modify
- private javax.swing.JButton jButton1;
- private com.toedter.calendar.JDateChooser jDateChooser1;
- // End of variables declaration
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement