rootUser

[DB][3.1] MemoryDetails.java (SSMS)

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