Advertisement
rootUser

[DB][3.1] MemoryDetails.java

Jan 23rd, 2017
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 38.39 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package diary;
  7.  
  8. import java.awt.Color;
  9. import java.sql.Connection;
  10. //import java.sql.Date;
  11. //import java.util.Date;
  12. import java.sql.DriverManager;
  13. import java.sql.ResultSet;
  14. import java.sql.SQLException;
  15. import java.sql.Statement;
  16. import java.text.ParseException;
  17. import java.text.SimpleDateFormat;
  18. import javax.swing.JOptionPane;
  19.  
  20. /**
  21.  *
  22.  * @author root
  23.  */
  24. public class MemoryDetails extends javax.swing.JFrame
  25. {
  26.  
  27.     public int memoryID=0;
  28.     /**
  29.      * Creates new form MemoryDetails
  30.      */
  31.     public MemoryDetails()
  32.     {
  33.         initComponents();
  34.         getContentPane().setBackground(Color.ORANGE);
  35.         showResultDetails();
  36.  
  37.  
  38.     }
  39.     public MemoryDetails(int memoryID)
  40.     {
  41.         initComponents();
  42.         getContentPane().setBackground(Color.orange);
  43.         this.memoryID=memoryID;
  44.         showResultDetails();
  45.     }
  46.     public void showResultDetails()
  47.     {
  48.         String host = "jdbc:derby://localhost:1527/diary";
  49.         String username = "nbuser";
  50.         String password = "nbuser";
  51.         try
  52.         {
  53.             //connect database and fetch result
  54.             Connection connection = DriverManager.getConnection(host, username, password);
  55.             Statement statement = connection.createStatement();
  56.             ResultSet resultSet =
  57.                 statement.executeQuery
  58.                 (
  59.                     "SELECT memoryAll.MEMORYID, " +
  60.                     "       memoryAll.MEMORYNAME, " +
  61.                     "       memoryMoment.MEMORYMOMENTDATE, " +
  62.                     "       memoryMoment.MEMORYMOMENTTIME, " +
  63.                     "       memoryPlace.MEMORYPLACENAME,   " +
  64.                     "       memoryDescriptiON.MEMORYDESCRIPTIONFULL " +
  65.                     "FROM memoryAll " +
  66.                     "    JOIN memoryMoment " +
  67.                     "    ON memoryAll.MEMORYID=memoryMoment.MEMORYID "+
  68.                     "        JOIN memoryPlace " +
  69.                     "         ON memoryAll.MEMORYID=memoryPlace.MEMORYID "+
  70.                     "            JOIN MEMORYDESCRIPTION " +
  71.                     "            ON memoryAll.MEMORYID=memoryDescription.MEMORYID "+
  72.                     "WHERE memoryAll.MEMORYID="+memoryID
  73.                 );
  74.             //add result to ui - according to result
  75.             while(resultSet.next())
  76.             {
  77.                 //fetch
  78.                 int memoryID0 = resultSet.getInt("memoryID");
  79.                 String memoryName = resultSet.getString("memoryName");
  80.                 String memoryDate = resultSet.getString("memoryMomentDate");
  81.                 String memoryTime = resultSet.getString("memoryMomentTime");
  82.                 String memoryPlace= resultSet.getString("memoryPlaceName");
  83.                 String memoryDescription = resultSet.getString("memoryDescriptionFull");
  84.                 //display
  85.                 idTextField.setText(""+memoryID0);
  86.                 nameTextField.setText(""+memoryName);
  87.                 dateTextField.setText(""+memoryDate);
  88.                 timeTextField.setText(""+memoryTime);
  89.                 placeTextField.setText(""+memoryPlace);
  90.                 descriptionTextArea.setText(""+memoryDescription);
  91.  
  92.                 if(idTextField.getText().equals(""))
  93.                 {
  94.                     idTextField.setText(""+this.memoryID);
  95.                 }
  96.             }
  97.             //close all
  98.             resultSet.close();
  99.             statement.close();
  100.             connection.close();
  101.         }
  102.         catch(SQLException sqlException)
  103.         {
  104.             JOptionPane.showMessageDialog
  105.             (this,
  106.              "Error code : "+sqlException.getErrorCode()+"\n"+
  107.              "Error message : "+sqlException.getMessage()+"\n"+
  108.              "SQL state : "+sqlException.getSQLState()+"\n"
  109.             );
  110.         }
  111.     }
  112.  
  113.     /**
  114.      * This method is called from within the constructor to initialize the form.
  115.      * WARNING: Do NOT modify this code. The content of this method is always
  116.      * regenerated by the Form Editor.
  117.      */
  118.     @SuppressWarnings("unchecked")
  119.     // <editor-fold defaultstate="collapsed" desc="Generated Code">
  120.     private void initComponents()
  121.     {
  122.  
  123.         detailsLabel = new javax.swing.JLabel();
  124.         nameLabel = new javax.swing.JLabel();
  125.         placeLabel = new javax.swing.JLabel();
  126.         nameTextField = new javax.swing.JTextField();
  127.         placeTextField = new javax.swing.JTextField();
  128.         descriptionLabel = new javax.swing.JLabel();
  129.         descriptionScrollPane = new javax.swing.JScrollPane();
  130.         descriptionTextArea = new javax.swing.JTextArea();
  131.         idLabel = new javax.swing.JLabel();
  132.         idTextField = new javax.swing.JTextField();
  133.         backToAllMemoriesButton = new javax.swing.JButton();
  134.         backToMenuButton = new javax.swing.JButton();
  135.         exitButton = new javax.swing.JButton();
  136.         deleteMemoryButton = new javax.swing.JButton();
  137.         updateDescriptionButton = new javax.swing.JButton();
  138.         updatePlaceButton = new javax.swing.JButton();
  139.         updateNameButton = new javax.swing.JButton();
  140.         dateLabel = new javax.swing.JLabel();
  141.         dateTextField = new javax.swing.JTextField();
  142.         updateDateButton = new javax.swing.JButton();
  143.         timeLabel = new javax.swing.JLabel();
  144.         timeTextField = new javax.swing.JTextField();
  145.         updateTimeButton = new javax.swing.JButton();
  146.  
  147.         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  148.  
  149.         detailsLabel.setFont(new java.awt.Font("Kristen ITC", 1, 12)); // NOI18N
  150.         detailsLabel.setForeground(new java.awt.Color(255, 51, 0));
  151.         detailsLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
  152.         detailsLabel.setText("DETAILS");
  153.  
  154.         nameLabel.setFont(new java.awt.Font("Papyrus", 1, 12)); // NOI18N
  155.         nameLabel.setForeground(new java.awt.Color(0, 0, 255));
  156.         nameLabel.setText("NAME :");
  157.  
  158.         placeLabel.setFont(new java.awt.Font("Papyrus", 1, 12)); // NOI18N
  159.         placeLabel.setForeground(new java.awt.Color(0, 0, 255));
  160.         placeLabel.setText("PLACE :");
  161.         placeLabel.setToolTipText("");
  162.  
  163.         nameTextField.setBackground(new java.awt.Color(0, 0, 0));
  164.         nameTextField.setFont(new java.awt.Font("Lucida Console", 1, 12)); // NOI18N
  165.         nameTextField.setForeground(new java.awt.Color(0, 255, 0));
  166.         nameTextField.addActionListener(new java.awt.event.ActionListener()
  167.         {
  168.             public void actionPerformed(java.awt.event.ActionEvent evt)
  169.             {
  170.                 nameTextFieldActionPerformed(evt);
  171.             }
  172.         });
  173.  
  174.         placeTextField.setBackground(new java.awt.Color(0, 0, 0));
  175.         placeTextField.setFont(new java.awt.Font("Lucida Console", 1, 12)); // NOI18N
  176.         placeTextField.setForeground(new java.awt.Color(0, 255, 0));
  177.         placeTextField.addActionListener(new java.awt.event.ActionListener()
  178.         {
  179.             public void actionPerformed(java.awt.event.ActionEvent evt)
  180.             {
  181.                 placeTextFieldActionPerformed(evt);
  182.             }
  183.         });
  184.  
  185.         descriptionLabel.setFont(new java.awt.Font("Papyrus", 1, 12)); // NOI18N
  186.         descriptionLabel.setForeground(new java.awt.Color(0, 0, 255));
  187.         descriptionLabel.setText("DESCRIPTION :");
  188.  
  189.         descriptionTextArea.setBackground(new java.awt.Color(0, 0, 0));
  190.         descriptionTextArea.setColumns(20);
  191.         descriptionTextArea.setFont(new java.awt.Font("Lucida Console", 1, 12)); // NOI18N
  192.         descriptionTextArea.setForeground(new java.awt.Color(0, 255, 0));
  193.         descriptionTextArea.setRows(5);
  194.         descriptionScrollPane.setViewportView(descriptionTextArea);
  195.  
  196.         idLabel.setFont(new java.awt.Font("Papyrus", 1, 12)); // NOI18N
  197.         idLabel.setForeground(new java.awt.Color(0, 0, 255));
  198.         idLabel.setText("ID :");
  199.         idLabel.setToolTipText("");
  200.  
  201.         idTextField.setBackground(new java.awt.Color(0, 0, 0));
  202.         idTextField.setFont(new java.awt.Font("Lucida Console", 1, 12)); // NOI18N
  203.         idTextField.setForeground(new java.awt.Color(0, 255, 0));
  204.         idTextField.addActionListener(new java.awt.event.ActionListener()
  205.         {
  206.             public void actionPerformed(java.awt.event.ActionEvent evt)
  207.             {
  208.                 idTextFieldActionPerformed(evt);
  209.             }
  210.         });
  211.  
  212.         backToAllMemoriesButton.setBackground(new java.awt.Color(0, 0, 0));
  213.         backToAllMemoriesButton.setFont(new java.awt.Font("sansserif", 1, 12)); // NOI18N
  214.         backToAllMemoriesButton.setForeground(new java.awt.Color(0, 255, 0));
  215.         backToAllMemoriesButton.setText("BACK TO ALL MEMORIES");
  216.         backToAllMemoriesButton.addActionListener(new java.awt.event.ActionListener()
  217.         {
  218.             public void actionPerformed(java.awt.event.ActionEvent evt)
  219.             {
  220.                 backToAllMemoriesButtonActionPerformed(evt);
  221.             }
  222.         });
  223.  
  224.         backToMenuButton.setBackground(new java.awt.Color(0, 0, 0));
  225.         backToMenuButton.setFont(new java.awt.Font("sansserif", 1, 12)); // NOI18N
  226.         backToMenuButton.setForeground(new java.awt.Color(0, 255, 0));
  227.         backToMenuButton.setText("BACK TO MENU");
  228.         backToMenuButton.addActionListener(new java.awt.event.ActionListener()
  229.         {
  230.             public void actionPerformed(java.awt.event.ActionEvent evt)
  231.             {
  232.                 backToMenuButtonActionPerformed(evt);
  233.             }
  234.         });
  235.  
  236.         exitButton.setBackground(new java.awt.Color(0, 0, 0));
  237.         exitButton.setFont(new java.awt.Font("sansserif", 1, 12)); // NOI18N
  238.         exitButton.setForeground(new java.awt.Color(0, 255, 0));
  239.         exitButton.setText("EXIT");
  240.         exitButton.addActionListener(new java.awt.event.ActionListener()
  241.         {
  242.             public void actionPerformed(java.awt.event.ActionEvent evt)
  243.             {
  244.                 exitButtonActionPerformed(evt);
  245.             }
  246.         });
  247.  
  248.         deleteMemoryButton.setBackground(new java.awt.Color(0, 0, 0));
  249.         deleteMemoryButton.setFont(new java.awt.Font("sansserif", 1, 12)); // NOI18N
  250.         deleteMemoryButton.setForeground(new java.awt.Color(0, 255, 0));
  251.         deleteMemoryButton.setText("DELETE MEMORY");
  252.         deleteMemoryButton.addActionListener(new java.awt.event.ActionListener()
  253.         {
  254.             public void actionPerformed(java.awt.event.ActionEvent evt)
  255.             {
  256.                 deleteMemoryButtonActionPerformed(evt);
  257.             }
  258.         });
  259.  
  260.         updateDescriptionButton.setBackground(new java.awt.Color(0, 0, 0));
  261.         updateDescriptionButton.setFont(new java.awt.Font("sansserif", 1, 12)); // NOI18N
  262.         updateDescriptionButton.setForeground(new java.awt.Color(0, 255, 0));
  263.         updateDescriptionButton.setText("UPDATE");
  264.         updateDescriptionButton.addActionListener(new java.awt.event.ActionListener()
  265.         {
  266.             public void actionPerformed(java.awt.event.ActionEvent evt)
  267.             {
  268.                 updateDescriptionButtonActionPerformed(evt);
  269.             }
  270.         });
  271.  
  272.         updatePlaceButton.setBackground(new java.awt.Color(0, 0, 0));
  273.         updatePlaceButton.setFont(new java.awt.Font("sansserif", 1, 12)); // NOI18N
  274.         updatePlaceButton.setForeground(new java.awt.Color(0, 255, 0));
  275.         updatePlaceButton.setText("UPDATE");
  276.         updatePlaceButton.addActionListener(new java.awt.event.ActionListener()
  277.         {
  278.             public void actionPerformed(java.awt.event.ActionEvent evt)
  279.             {
  280.                 updatePlaceButtonActionPerformed(evt);
  281.             }
  282.         });
  283.  
  284.         updateNameButton.setBackground(new java.awt.Color(0, 0, 0));
  285.         updateNameButton.setFont(new java.awt.Font("sansserif", 1, 12)); // NOI18N
  286.         updateNameButton.setForeground(new java.awt.Color(0, 255, 0));
  287.         updateNameButton.setText("UPDATE");
  288.         updateNameButton.addActionListener(new java.awt.event.ActionListener()
  289.         {
  290.             public void actionPerformed(java.awt.event.ActionEvent evt)
  291.             {
  292.                 updateNameButtonActionPerformed(evt);
  293.             }
  294.         });
  295.  
  296.         dateLabel.setFont(new java.awt.Font("Papyrus", 1, 12)); // NOI18N
  297.         dateLabel.setForeground(new java.awt.Color(0, 0, 255));
  298.         dateLabel.setText("DATE :");
  299.  
  300.         dateTextField.setBackground(new java.awt.Color(0, 0, 0));
  301.         dateTextField.setFont(new java.awt.Font("Lucida Console", 1, 12)); // NOI18N
  302.         dateTextField.setForeground(new java.awt.Color(0, 255, 0));
  303.         dateTextField.addActionListener(new java.awt.event.ActionListener()
  304.         {
  305.             public void actionPerformed(java.awt.event.ActionEvent evt)
  306.             {
  307.                 dateTextFieldActionPerformed(evt);
  308.             }
  309.         });
  310.  
  311.         updateDateButton.setBackground(new java.awt.Color(0, 0, 0));
  312.         updateDateButton.setFont(new java.awt.Font("sansserif", 1, 12)); // NOI18N
  313.         updateDateButton.setForeground(new java.awt.Color(0, 255, 0));
  314.         updateDateButton.setText("UPDATE");
  315.         updateDateButton.addActionListener(new java.awt.event.ActionListener()
  316.         {
  317.             public void actionPerformed(java.awt.event.ActionEvent evt)
  318.             {
  319.                 updateDateButtonActionPerformed(evt);
  320.             }
  321.         });
  322.  
  323.         timeLabel.setFont(new java.awt.Font("Papyrus", 1, 12)); // NOI18N
  324.         timeLabel.setForeground(new java.awt.Color(0, 0, 255));
  325.         timeLabel.setText("TIME :");
  326.  
  327.         timeTextField.setBackground(new java.awt.Color(0, 0, 0));
  328.         timeTextField.setFont(new java.awt.Font("Lucida Console", 1, 12)); // NOI18N
  329.         timeTextField.setForeground(new java.awt.Color(0, 255, 0));
  330.         timeTextField.addActionListener(new java.awt.event.ActionListener()
  331.         {
  332.             public void actionPerformed(java.awt.event.ActionEvent evt)
  333.             {
  334.                 timeTextFieldActionPerformed(evt);
  335.             }
  336.         });
  337.  
  338.         updateTimeButton.setBackground(new java.awt.Color(0, 0, 0));
  339.         updateTimeButton.setFont(new java.awt.Font("sansserif", 1, 12)); // NOI18N
  340.         updateTimeButton.setForeground(new java.awt.Color(0, 255, 0));
  341.         updateTimeButton.setText("UPDATE");
  342.         updateTimeButton.addActionListener(new java.awt.event.ActionListener()
  343.         {
  344.             public void actionPerformed(java.awt.event.ActionEvent evt)
  345.             {
  346.                 updateTimeButtonActionPerformed(evt);
  347.             }
  348.         });
  349.  
  350.         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  351.         getContentPane().setLayout(layout);
  352.         layout.setHorizontalGroup(
  353.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  354.             .addGroup(layout.createSequentialGroup()
  355.                       .addContainerGap()
  356.                       .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  357.                                 .addComponent(timeLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  358.                                 .addComponent(idLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  359.                                 .addComponent(detailsLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  360.                                 .addComponent(nameLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  361.                                 .addComponent(placeLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  362.                                 .addComponent(dateLabel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  363.                                 .addGroup(layout.createSequentialGroup()
  364.                                           .addComponent(nameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 455, javax.swing.GroupLayout.PREFERRED_SIZE)
  365.                                           .addGap(18, 18, 18)
  366.                                           .addComponent(updateNameButton)
  367.                                           .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  368.                                 .addComponent(descriptionLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  369.                                 .addGroup(layout.createSequentialGroup()
  370.                                           .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  371.                                                   .addGroup(layout.createSequentialGroup()
  372.                                                           .addComponent(placeTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 456, javax.swing.GroupLayout.PREFERRED_SIZE)
  373.                                                           .addGap(18, 18, 18)
  374.                                                           .addComponent(updatePlaceButton))
  375.                                                   .addGroup(layout.createSequentialGroup()
  376.                                                           .addComponent(dateTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 457, javax.swing.GroupLayout.PREFERRED_SIZE)
  377.                                                           .addGap(18, 18, 18)
  378.                                                           .addComponent(updateDateButton))
  379.                                                   .addGroup(layout.createSequentialGroup()
  380.                                                           .addComponent(timeTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 455, javax.swing.GroupLayout.PREFERRED_SIZE)
  381.                                                           .addGap(18, 18, 18)
  382.                                                           .addComponent(updateTimeButton))
  383.                                                   .addGroup(layout.createSequentialGroup()
  384.                                                           .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
  385.                                                                   .addComponent(deleteMemoryButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  386.                                                                   .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  387.                                                                           .addComponent(backToAllMemoriesButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  388.                                                                           .addGap(18, 18, 18)
  389.                                                                           .addComponent(backToMenuButton, javax.swing.GroupLayout.PREFERRED_SIZE, 205, javax.swing.GroupLayout.PREFERRED_SIZE))
  390.                                                                   .addComponent(descriptionScrollPane, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 455, javax.swing.GroupLayout.PREFERRED_SIZE))
  391.                                                           .addGap(18, 18, 18)
  392.                                                           .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  393.                                                                   .addComponent(exitButton, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE)
  394.                                                                   .addComponent(updateDescriptionButton)))
  395.                                                   .addComponent(idTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 545, javax.swing.GroupLayout.PREFERRED_SIZE))
  396.                                           .addGap(0, 22, Short.MAX_VALUE))))
  397.         );
  398.         layout.setVerticalGroup(
  399.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  400.             .addGroup(layout.createSequentialGroup()
  401.                       .addContainerGap()
  402.                       .addComponent(detailsLabel)
  403.                       .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  404.                       .addComponent(idLabel)
  405.                       .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  406.                       .addComponent(idTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  407.                       .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  408.                       .addComponent(nameLabel)
  409.                       .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  410.                       .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  411.                                 .addComponent(nameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  412.                                 .addComponent(updateNameButton))
  413.                       .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  414.                       .addComponent(dateLabel)
  415.                       .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  416.                       .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  417.                                 .addComponent(dateTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  418.                                 .addComponent(updateDateButton))
  419.                       .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  420.                       .addComponent(timeLabel)
  421.                       .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  422.                       .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  423.                                 .addComponent(timeTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  424.                                 .addComponent(updateTimeButton))
  425.                       .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  426.                       .addComponent(placeLabel)
  427.                       .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  428.                       .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  429.                                 .addComponent(placeTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  430.                                 .addComponent(updatePlaceButton))
  431.                       .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  432.                       .addComponent(descriptionLabel)
  433.                       .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  434.                       .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
  435.                                 .addComponent(descriptionScrollPane)
  436.                                 .addComponent(updateDescriptionButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  437.                       .addGap(18, 18, 18)
  438.                       .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
  439.                                 .addGroup(layout.createSequentialGroup()
  440.                                           .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  441.                                                   .addComponent(backToAllMemoriesButton)
  442.                                                   .addComponent(backToMenuButton))
  443.                                           .addGap(18, 18, 18)
  444.                                           .addComponent(deleteMemoryButton))
  445.                                 .addComponent(exitButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  446.                       .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  447.         );
  448.  
  449.         pack();
  450.         setLocationRelativeTo(null);
  451.     }// </editor-fold>
  452.  
  453.     private void nameTextFieldActionPerformed(java.awt.event.ActionEvent evt)
  454.     {
  455.         // TODO add your handling code here:
  456.     }
  457.  
  458.     private void idTextFieldActionPerformed(java.awt.event.ActionEvent evt)
  459.     {
  460.         // TODO add your handling code here:
  461.     }
  462.  
  463.     private void placeTextFieldActionPerformed(java.awt.event.ActionEvent evt)
  464.     {
  465.         // TODO add your handling code here:
  466.     }
  467.  
  468.     private void backToAllMemoriesButtonActionPerformed(java.awt.event.ActionEvent evt)
  469.     {
  470.         // TODO add your handling code here:
  471.         this.setVisible(false);
  472.         MemoryIndex memoryIndex = new MemoryIndex();
  473.         memoryIndex.setVisible(true);
  474.     }
  475.  
  476.     private void exitButtonActionPerformed(java.awt.event.ActionEvent evt)
  477.     {
  478.         // TODO add your handling code here:
  479.         System.exit(0);
  480.     }
  481.  
  482.     private void updateNameButtonActionPerformed(java.awt.event.ActionEvent evt)
  483.     {
  484.         // TODO add your handling code here:
  485.         String host = "jdbc:derby://localhost:1527/diary";
  486.         String username = "nbuser";
  487.         String password = "nbuser";
  488.         try
  489.         {
  490.             //fetch result
  491.             String inputName = nameTextField.getText();
  492.             //connect database and fetch result
  493.             Connection connection = DriverManager.getConnection(host, username, password);
  494.             Statement statement = connection.createStatement();
  495.             statement.executeUpdate
  496.             (
  497.                 " UPDATE memoryAll " +
  498.                 " SET memoryName=' " +inputName+" ' "+
  499.                 " WHERE memoryID=" +this.memoryID
  500.             );
  501.             //close all
  502.             statement.close();
  503.             connection.close();
  504.         }
  505.         catch(SQLException sqlException)
  506.         {
  507.             sqlException.printStackTrace();
  508.             JOptionPane.showMessageDialog
  509.             (this,
  510.              "Error code : "+sqlException.getErrorCode()+"\n"+
  511.              "Error message : "+sqlException.getMessage()+"\n"+
  512.              "SQL state : "+sqlException.getSQLState()+"\n"
  513.             );
  514.         }
  515.         this.setVisible(false);
  516.         MemoryIndex memoryIndex = new MemoryIndex();
  517.         memoryIndex.setVisible(true);
  518.     }
  519.  
  520.     private void deleteMemoryButtonActionPerformed(java.awt.event.ActionEvent evt)
  521.     {
  522.         // TODO add your handling code here:
  523.         String host = "jdbc:derby://localhost:1527/diary";
  524.         String username = "nbuser";
  525.         String password = "nbuser";
  526.         try
  527.         {
  528.             //connect database and fetch result
  529.             Connection connection = DriverManager.getConnection(host, username, password);
  530.             Statement statement = connection.createStatement();
  531.             statement.executeUpdate
  532.             (
  533.                 "DELETE FROM memoryAll " +
  534.                 "WHERE memoryID=" +this.memoryID
  535.             );
  536.             //close all
  537.             statement.close();
  538.             connection.close();
  539.         }
  540.         catch(SQLException sqlException)
  541.         {
  542.             JOptionPane.showMessageDialog
  543.             (this,
  544.              "Error code : "+sqlException.getErrorCode()+"\n"+
  545.              "Error message : "+sqlException.getMessage()+"\n"+
  546.              "SQL state : "+sqlException.getSQLState()+"\n"
  547.             );
  548.         }
  549.         this.setVisible(false);
  550.         MemoryIndex memoryIndex = new MemoryIndex();
  551.         memoryIndex.setVisible(true);
  552.     }
  553.  
  554.     private void updateTimeButtonActionPerformed(java.awt.event.ActionEvent evt)
  555.     {
  556.         // TODO add your handling code here:
  557.         String host = "jdbc:derby://localhost:1527/diary";
  558.         String username = "nbuser";
  559.         String password = "nbuser";
  560.         try
  561.         {
  562.             //convert string to util time
  563.             String inputDate = timeTextField.getText();
  564.             SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");
  565.             java.util.Date utilDate = null;
  566.             utilDate = formatter.parse(inputDate);
  567.             //covert util date to sql date
  568.             java.sql.Time sqlDate = new java.sql.Time(utilDate.getTime());
  569.  
  570.             //connect database and fetch result
  571.             Connection connection = DriverManager.getConnection(host, username, password);
  572.             Statement statement = connection.createStatement();
  573.             statement.executeUpdate
  574.             (
  575.                 " UPDATE memoryMoment " +
  576.                 " SET memoryMomentTime=TIME('"+sqlDate+"')"+
  577.                 " WHERE memoryID=" +this.memoryID
  578.             );
  579.             //close all
  580.             statement.close();
  581.             connection.close();
  582.         }
  583.         catch(SQLException sqlException)
  584.         {
  585.             sqlException.printStackTrace();
  586.             JOptionPane.showMessageDialog
  587.             (this,
  588.              "Error code : "+sqlException.getErrorCode()+"\n"+
  589.              "Error message : "+sqlException.getMessage()+"\n"+
  590.              "SQL state : "+sqlException.getSQLState()+"\n"
  591.             );
  592.         }
  593.         catch (ParseException parseException)
  594.         {
  595.             parseException.printStackTrace();
  596.             JOptionPane.showMessageDialog
  597.             (this,
  598.              "Error message : "+parseException.getMessage()+"\n"+
  599.              "Error offset : "+parseException.getErrorOffset()+"\n"
  600.             );
  601.         }
  602.         this.setVisible(false);
  603.         MemoryIndex memoryIndex = new MemoryIndex();
  604.         memoryIndex.setVisible(true);
  605.  
  606.     }
  607.  
  608.     private void backToMenuButtonActionPerformed(java.awt.event.ActionEvent evt)
  609.     {
  610.         // TODO add your handling code here:
  611.         this.setVisible(false);
  612.         Menu menu = new Menu();
  613.         menu.setVisible(true);
  614.     }
  615.  
  616.     private void timeTextFieldActionPerformed(java.awt.event.ActionEvent evt)
  617.     {
  618.         // TODO add your handling code here:
  619.     }
  620.  
  621.     private void updateDateButtonActionPerformed(java.awt.event.ActionEvent evt)
  622.     {
  623.         // TODO add your handling code here:
  624.         String host = "jdbc:derby://localhost:1527/diary";
  625.         String username = "nbuser";
  626.         String password = "nbuser";
  627.         try
  628.         {
  629.             //convert string to util date
  630.             String inputDate = dateTextField.getText();
  631.             SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
  632.             java.util.Date utilDate = null;
  633.             utilDate = formatter.parse(inputDate);
  634.             //covert util date to sql date
  635.             java.sql.Date sqlDate = new java.sql.Date(utilDate.getTime());
  636.             //connect database and fetch result
  637.             Connection connection = DriverManager.getConnection(host, username, password);
  638.             Statement statement = connection.createStatement();
  639.             statement.executeUpdate
  640.             (
  641.                 " UPDATE memoryMoment " +
  642.                 " SET memoryMomentDate=DATE('"+sqlDate+"')"+
  643.                 " WHERE memoryID=" +this.memoryID
  644.             );
  645.             //close all
  646.             statement.close();
  647.             connection.close();
  648.         }
  649.         catch(SQLException sqlException)
  650.         {
  651.             sqlException.printStackTrace();
  652.             JOptionPane.showMessageDialog
  653.             (this,
  654.              "Error code : "+sqlException.getErrorCode()+"\n"+
  655.              "Error message : "+sqlException.getMessage()+"\n"+
  656.              "SQL state : "+sqlException.getSQLState()+"\n"
  657.             );
  658.         }
  659.         catch (ParseException parseException)
  660.         {
  661.             parseException.printStackTrace();
  662.             JOptionPane.showMessageDialog
  663.             (this,
  664.              "Error message : "+parseException.getMessage()+"\n"+
  665.              "Error offset : "+parseException.getErrorOffset()+"\n"
  666.             );
  667.         }
  668.         this.setVisible(false);
  669.         MemoryIndex memoryIndex = new MemoryIndex();
  670.         memoryIndex.setVisible(true);
  671.     }
  672.  
  673.     private void dateTextFieldActionPerformed(java.awt.event.ActionEvent evt)
  674.     {
  675.         // TODO add your handling code here:
  676.     }
  677.  
  678.     private void updateDescriptionButtonActionPerformed(java.awt.event.ActionEvent evt)
  679.     {
  680.         // TODO add your handling code here:
  681.         String host = "jdbc:derby://localhost:1527/diary";
  682.         String username = "nbuser";
  683.         String password = "nbuser";
  684.         try
  685.         {
  686.             //fetch result
  687.             String inputDescription = descriptionTextArea.getText();
  688.             //connect database and fetch result
  689.             Connection connection = DriverManager.getConnection(host, username, password);
  690.             Statement statement = connection.createStatement();
  691.             statement.executeUpdate
  692.             (
  693.                 " UPDATE memoryDescription " +
  694.                 " SET memoryDescriptionFull=' " +inputDescription+" ' "+
  695.                 " WHERE memoryID=" +this.memoryID
  696.             );
  697.             //close all
  698.             statement.close();
  699.             connection.close();
  700.         }
  701.         catch(SQLException sqlException)
  702.         {
  703.             sqlException.printStackTrace();
  704.             JOptionPane.showMessageDialog
  705.             (this,
  706.              "Error code : "+sqlException.getErrorCode()+"\n"+
  707.              "Error message : "+sqlException.getMessage()+"\n"+
  708.              "SQL state : "+sqlException.getSQLState()+"\n"
  709.             );
  710.         }
  711.         this.setVisible(false);
  712.         MemoryIndex memoryIndex = new MemoryIndex();
  713.         memoryIndex.setVisible(true);
  714.     }
  715.  
  716.     private void updatePlaceButtonActionPerformed(java.awt.event.ActionEvent evt)
  717.     {
  718.         // TODO add your handling code here:
  719.         String host = "jdbc:derby://localhost:1527/diary";
  720.         String username = "nbuser";
  721.         String password = "nbuser";
  722.         try
  723.         {
  724.             //fetch result
  725.             String inputPlace = placeTextField.getText();
  726.             //connect database and fetch result
  727.             Connection connection = DriverManager.getConnection(host, username, password);
  728.             Statement statement = connection.createStatement();
  729.             statement.executeUpdate
  730.             (
  731.                 " UPDATE memoryPlace " +
  732.                 " SET memoryPlaceName=' " +inputPlace+" ' "+
  733.                 " WHERE memoryID=" +this.memoryID
  734.             );
  735.             //close all
  736.             statement.close();
  737.             connection.close();
  738.         }
  739.         catch(SQLException sqlException)
  740.         {
  741.             sqlException.printStackTrace();
  742.             JOptionPane.showMessageDialog
  743.             (this,
  744.              "Error code : "+sqlException.getErrorCode()+"\n"+
  745.              "Error message : "+sqlException.getMessage()+"\n"+
  746.              "SQL state : "+sqlException.getSQLState()+"\n"
  747.             );
  748.         }
  749.         this.setVisible(false);
  750.         MemoryIndex memoryIndex = new MemoryIndex();
  751.         memoryIndex.setVisible(true);
  752.     }
  753.  
  754.     /**
  755.      * @param args the command line arguments
  756.      */
  757.     public static void main(String args[])
  758.     {
  759.         /* Set the Nimbus look and feel */
  760.         //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  761.         /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  762.          * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  763.          */
  764.         try
  765.         {
  766.             for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels())
  767.             {
  768.                 if ("Nimbus".equals(info.getName()))
  769.                 {
  770.                     javax.swing.UIManager.setLookAndFeel(info.getClassName());
  771.                     break;
  772.                 }
  773.             }
  774.         }
  775.         catch (ClassNotFoundException ex)
  776.         {
  777.             java.util.logging.Logger.getLogger(MemoryDetails.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  778.         }
  779.         catch (InstantiationException ex)
  780.         {
  781.             java.util.logging.Logger.getLogger(MemoryDetails.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  782.         }
  783.         catch (IllegalAccessException ex)
  784.         {
  785.             java.util.logging.Logger.getLogger(MemoryDetails.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  786.         }
  787.         catch (javax.swing.UnsupportedLookAndFeelException ex)
  788.         {
  789.             java.util.logging.Logger.getLogger(MemoryDetails.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  790.         }
  791.         //</editor-fold>
  792.  
  793.         /* Create and display the form */
  794.         java.awt.EventQueue.invokeLater(new Runnable()
  795.         {
  796.             public void run()
  797.             {
  798.                 new MemoryDetails().setVisible(true);
  799.             }
  800.         });
  801.     }
  802.  
  803.     // Variables declaration - do not modify
  804.     private javax.swing.JButton backToAllMemoriesButton;
  805.     private javax.swing.JButton backToMenuButton;
  806.     private javax.swing.JLabel dateLabel;
  807.     private javax.swing.JTextField dateTextField;
  808.     private javax.swing.JButton deleteMemoryButton;
  809.     private javax.swing.JLabel descriptionLabel;
  810.     private javax.swing.JScrollPane descriptionScrollPane;
  811.     private javax.swing.JTextArea descriptionTextArea;
  812.     private javax.swing.JLabel detailsLabel;
  813.     private javax.swing.JButton exitButton;
  814.     private javax.swing.JLabel idLabel;
  815.     private javax.swing.JTextField idTextField;
  816.     private javax.swing.JLabel nameLabel;
  817.     private javax.swing.JTextField nameTextField;
  818.     private javax.swing.JLabel placeLabel;
  819.     private javax.swing.JTextField placeTextField;
  820.     private javax.swing.JLabel timeLabel;
  821.     private javax.swing.JTextField timeTextField;
  822.     private javax.swing.JButton updateDateButton;
  823.     private javax.swing.JButton updateDescriptionButton;
  824.     private javax.swing.JButton updateNameButton;
  825.     private javax.swing.JButton updatePlaceButton;
  826.     private javax.swing.JButton updateTimeButton;
  827.     // End of variables declaration
  828. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement