Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package diary;
- import java.awt.Color;
- import java.sql.Connection;
- //import java.sql.Date;
- //import java.util.Date;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import java.text.ParseException;
- import java.text.SimpleDateFormat;
- import javax.swing.JOptionPane;
- /**
- *
- * @author root
- */
- public class MemoryDetails extends javax.swing.JFrame
- {
- public int memoryID=0;
- /**
- * Creates new form MemoryDetails
- */
- public MemoryDetails()
- {
- initComponents();
- getContentPane().setBackground(Color.ORANGE);
- showResultDetails();
- }
- public MemoryDetails(int memoryID)
- {
- initComponents();
- getContentPane().setBackground(Color.orange);
- this.memoryID=memoryID;
- showResultDetails();
- }
- public void showResultDetails()
- {
- String driver="com.microsoft.sqlserver.jdbc.SQLServerDriver";
- String host = "jdbc:sqlserver://localhost:61271";
- String username = "sa";
- String password = "alvi";
- try
- {
- //connect database and fetch result
- Class.forName(driver);
- Connection connection = DriverManager.getConnection(host, username, password);
- Statement statement = connection.createStatement();
- ResultSet resultSet =
- statement.executeQuery
- (
- "SELECT diary.dbo.memoryAll.MEMORYID, " +
- " diary.dbo.memoryAll.MEMORYNAME, " +
- " diary.dbo.memoryMoment.MEMORYMOMENTDATE, " +
- " diary.dbo.memoryMoment.MEMORYMOMENTTIME, " +
- " diary.dbo.memoryPlace.MEMORYPLACENAME, " +
- " diary.dbo.memoryDescription.MEMORYDESCRIPTIONFULL " +
- "FROM diary.dbo.memoryAll " +
- " JOIN diary.dbo.memoryMoment " +
- " ON diary.dbo.memoryAll.MEMORYID=diary.dbo.memoryMoment.MEMORYID "+
- " JOIN diary.dbo.memoryPlace " +
- " ON diary.dbo.memoryAll.MEMORYID=diary.dbo.memoryPlace.MEMORYID "+
- " JOIN diary.dbo.memoryDescription " +
- " ON diary.dbo.memoryAll.MEMORYID=diary.dbo.memoryDescription.MEMORYID "+
- "WHERE diary.dbo.memoryAll.MEMORYID="+memoryID
- );
- //add result to ui - according to result
- while(resultSet.next())
- {
- //fetch
- int memoryID0 = resultSet.getInt("memoryID");
- String memoryName = resultSet.getString("memoryName");
- String memoryDate = resultSet.getString("memoryMomentDate");
- String memoryTime = resultSet.getString("memoryMomentTime");
- String memoryPlace= resultSet.getString("memoryPlaceName");
- String memoryDescription = resultSet.getString("memoryDescriptionFull");
- //display
- idTextField.setText(""+memoryID0);
- nameTextField.setText(""+memoryName);
- dateTextField.setText(""+memoryDate);
- timeTextField.setText(""+memoryTime);
- placeTextField.setText(""+memoryPlace);
- descriptionTextArea.setText(""+memoryDescription);
- if(idTextField.getText().equals(""))
- {
- idTextField.setText(""+this.memoryID);
- }
- }
- //close all
- resultSet.close();
- statement.close();
- connection.close();
- }
- catch(SQLException sqlException)
- {
- sqlException.printStackTrace();
- JOptionPane.showMessageDialog
- (this,
- "Error code : "+sqlException.getErrorCode()+"\n"+
- "Error message : "+sqlException.getMessage()+"\n"+
- "SQL state : "+sqlException.getSQLState()+"\n"
- );
- }
- catch (ClassNotFoundException classNotFoundException)
- {
- classNotFoundException.printStackTrace();
- JOptionPane.showMessageDialog
- (this,
- "Error message : "+classNotFoundException.getMessage()+"\n"
- );
- }
- }
- /**
- * This method is called from within the constructor to initialize the form.
- * WARNING: Do NOT modify this code. The content of this method is always
- * regenerated by the Form Editor.
- */
- @SuppressWarnings("unchecked")
- // <editor-fold defaultstate="collapsed" desc="Generated Code">
- private void initComponents()
- {
- detailsLabel = new javax.swing.JLabel();
- nameLabel = new javax.swing.JLabel();
- placeLabel = new javax.swing.JLabel();
- nameTextField = new javax.swing.JTextField();
- placeTextField = new javax.swing.JTextField();
- descriptionLabel = new javax.swing.JLabel();
- descriptionScrollPane = new javax.swing.JScrollPane();
- descriptionTextArea = new javax.swing.JTextArea();
- idLabel = new javax.swing.JLabel();
- idTextField = new javax.swing.JTextField();
- backToAllMemoriesButton = new javax.swing.JButton();
- backToMenuButton = new javax.swing.JButton();
- exitButton = new javax.swing.JButton();
- deleteMemoryButton = new javax.swing.JButton();
- updateDescriptionButton = new javax.swing.JButton();
- updatePlaceButton = new javax.swing.JButton();
- updateNameButton = new javax.swing.JButton();
- dateLabel = new javax.swing.JLabel();
- dateTextField = new javax.swing.JTextField();
- updateDateButton = new javax.swing.JButton();
- timeLabel = new javax.swing.JLabel();
- timeTextField = new javax.swing.JTextField();
- updateTimeButton = new javax.swing.JButton();
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- detailsLabel.setFont(new java.awt.Font("Kristen ITC", 1, 12)); // NOI18N
- detailsLabel.setForeground(new java.awt.Color(255, 51, 0));
- detailsLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
- detailsLabel.setText("DETAILS");
- nameLabel.setFont(new java.awt.Font("Papyrus", 1, 12)); // NOI18N
- nameLabel.setForeground(new java.awt.Color(0, 0, 255));
- nameLabel.setText("NAME :");
- placeLabel.setFont(new java.awt.Font("Papyrus", 1, 12)); // NOI18N
- placeLabel.setForeground(new java.awt.Color(0, 0, 255));
- placeLabel.setText("PLACE :");
- placeLabel.setToolTipText("");
- nameTextField.setBackground(new java.awt.Color(0, 0, 0));
- nameTextField.setFont(new java.awt.Font("Lucida Console", 1, 12)); // NOI18N
- nameTextField.setForeground(new java.awt.Color(0, 255, 0));
- nameTextField.addActionListener(new java.awt.event.ActionListener()
- {
- public void actionPerformed(java.awt.event.ActionEvent evt)
- {
- nameTextFieldActionPerformed(evt);
- }
- });
- placeTextField.setBackground(new java.awt.Color(0, 0, 0));
- placeTextField.setFont(new java.awt.Font("Lucida Console", 1, 12)); // NOI18N
- placeTextField.setForeground(new java.awt.Color(0, 255, 0));
- placeTextField.addActionListener(new java.awt.event.ActionListener()
- {
- public void actionPerformed(java.awt.event.ActionEvent evt)
- {
- placeTextFieldActionPerformed(evt);
- }
- });
- descriptionLabel.setFont(new java.awt.Font("Papyrus", 1, 12)); // NOI18N
- descriptionLabel.setForeground(new java.awt.Color(0, 0, 255));
- descriptionLabel.setText("DESCRIPTION :");
- descriptionTextArea.setBackground(new java.awt.Color(0, 0, 0));
- descriptionTextArea.setColumns(20);
- descriptionTextArea.setFont(new java.awt.Font("Lucida Console", 1, 12)); // NOI18N
- descriptionTextArea.setForeground(new java.awt.Color(0, 255, 0));
- descriptionTextArea.setRows(5);
- descriptionScrollPane.setViewportView(descriptionTextArea);
- idLabel.setFont(new java.awt.Font("Papyrus", 1, 12)); // NOI18N
- idLabel.setForeground(new java.awt.Color(0, 0, 255));
- idLabel.setText("ID :");
- idLabel.setToolTipText("");
- idTextField.setBackground(new java.awt.Color(0, 0, 0));
- idTextField.setFont(new java.awt.Font("Lucida Console", 1, 12)); // NOI18N
- idTextField.setForeground(new java.awt.Color(0, 255, 0));
- idTextField.addActionListener(new java.awt.event.ActionListener()
- {
- public void actionPerformed(java.awt.event.ActionEvent evt)
- {
- idTextFieldActionPerformed(evt);
- }
- });
- backToAllMemoriesButton.setBackground(new java.awt.Color(0, 0, 0));
- backToAllMemoriesButton.setFont(new java.awt.Font("sansserif", 1, 12)); // NOI18N
- backToAllMemoriesButton.setForeground(new java.awt.Color(0, 255, 0));
- backToAllMemoriesButton.setText("BACK TO ALL MEMORIES");
- backToAllMemoriesButton.addActionListener(new java.awt.event.ActionListener()
- {
- public void actionPerformed(java.awt.event.ActionEvent evt)
- {
- backToAllMemoriesButtonActionPerformed(evt);
- }
- });
- backToMenuButton.setBackground(new java.awt.Color(0, 0, 0));
- backToMenuButton.setFont(new java.awt.Font("sansserif", 1, 12)); // NOI18N
- backToMenuButton.setForeground(new java.awt.Color(0, 255, 0));
- backToMenuButton.setText("BACK TO MENU");
- backToMenuButton.addActionListener(new java.awt.event.ActionListener()
- {
- public void actionPerformed(java.awt.event.ActionEvent evt)
- {
- backToMenuButtonActionPerformed(evt);
- }
- });
- exitButton.setBackground(new java.awt.Color(0, 0, 0));
- exitButton.setFont(new java.awt.Font("sansserif", 1, 12)); // NOI18N
- exitButton.setForeground(new java.awt.Color(0, 255, 0));
- exitButton.setText("EXIT");
- exitButton.addActionListener(new java.awt.event.ActionListener()
- {
- public void actionPerformed(java.awt.event.ActionEvent evt)
- {
- exitButtonActionPerformed(evt);
- }
- });
- deleteMemoryButton.setBackground(new java.awt.Color(0, 0, 0));
- deleteMemoryButton.setFont(new java.awt.Font("sansserif", 1, 12)); // NOI18N
- deleteMemoryButton.setForeground(new java.awt.Color(0, 255, 0));
- deleteMemoryButton.setText("DELETE MEMORY");
- deleteMemoryButton.addActionListener(new java.awt.event.ActionListener()
- {
- public void actionPerformed(java.awt.event.ActionEvent evt)
- {
- deleteMemoryButtonActionPerformed(evt);
- }
- });
- updateDescriptionButton.setBackground(new java.awt.Color(0, 0, 0));
- updateDescriptionButton.setFont(new java.awt.Font("sansserif", 1, 12)); // NOI18N
- updateDescriptionButton.setForeground(new java.awt.Color(0, 255, 0));
- updateDescriptionButton.setText("UPDATE");
- updateDescriptionButton.addActionListener(new java.awt.event.ActionListener()
- {
- public void actionPerformed(java.awt.event.ActionEvent evt)
- {
- updateDescriptionButtonActionPerformed(evt);
- }
- });
- updatePlaceButton.setBackground(new java.awt.Color(0, 0, 0));
- updatePlaceButton.setFont(new java.awt.Font("sansserif", 1, 12)); // NOI18N
- updatePlaceButton.setForeground(new java.awt.Color(0, 255, 0));
- updatePlaceButton.setText("UPDATE");
- updatePlaceButton.addActionListener(new java.awt.event.ActionListener()
- {
- public void actionPerformed(java.awt.event.ActionEvent evt)
- {
- updatePlaceButtonActionPerformed(evt);
- }
- });
- updateNameButton.setBackground(new java.awt.Color(0, 0, 0));
- updateNameButton.setFont(new java.awt.Font("sansserif", 1, 12)); // NOI18N
- updateNameButton.setForeground(new java.awt.Color(0, 255, 0));
- updateNameButton.setText("UPDATE");
- updateNameButton.addActionListener(new java.awt.event.ActionListener()
- {
- public void actionPerformed(java.awt.event.ActionEvent evt)
- {
- updateNameButtonActionPerformed(evt);
- }
- });
- dateLabel.setFont(new java.awt.Font("Papyrus", 1, 12)); // NOI18N
- dateLabel.setForeground(new java.awt.Color(0, 0, 255));
- dateLabel.setText("DATE :");
- dateTextField.setBackground(new java.awt.Color(0, 0, 0));
- dateTextField.setFont(new java.awt.Font("Lucida Console", 1, 12)); // NOI18N
- dateTextField.setForeground(new java.awt.Color(0, 255, 0));
- dateTextField.addActionListener(new java.awt.event.ActionListener()
- {
- public void actionPerformed(java.awt.event.ActionEvent evt)
- {
- dateTextFieldActionPerformed(evt);
- }
- });
- updateDateButton.setBackground(new java.awt.Color(0, 0, 0));
- updateDateButton.setFont(new java.awt.Font("sansserif", 1, 12)); // NOI18N
- updateDateButton.setForeground(new java.awt.Color(0, 255, 0));
- updateDateButton.setText("UPDATE");
- updateDateButton.addActionListener(new java.awt.event.ActionListener()
- {
- public void actionPerformed(java.awt.event.ActionEvent evt)
- {
- updateDateButtonActionPerformed(evt);
- }
- });
- timeLabel.setFont(new java.awt.Font("Papyrus", 1, 12)); // NOI18N
- timeLabel.setForeground(new java.awt.Color(0, 0, 255));
- timeLabel.setText("TIME :");
- timeTextField.setBackground(new java.awt.Color(0, 0, 0));
- timeTextField.setFont(new java.awt.Font("Lucida Console", 1, 12)); // NOI18N
- timeTextField.setForeground(new java.awt.Color(0, 255, 0));
- timeTextField.addActionListener(new java.awt.event.ActionListener()
- {
- public void actionPerformed(java.awt.event.ActionEvent evt)
- {
- timeTextFieldActionPerformed(evt);
- }
- });
- updateTimeButton.setBackground(new java.awt.Color(0, 0, 0));
- updateTimeButton.setFont(new java.awt.Font("sansserif", 1, 12)); // NOI18N
- updateTimeButton.setForeground(new java.awt.Color(0, 255, 0));
- updateTimeButton.setText("UPDATE");
- updateTimeButton.addActionListener(new java.awt.event.ActionListener()
- {
- public void actionPerformed(java.awt.event.ActionEvent evt)
- {
- updateTimeButtonActionPerformed(evt);
- }
- });
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addContainerGap()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(timeLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(idLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(detailsLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(nameLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(placeLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(dateLabel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addGroup(layout.createSequentialGroup()
- .addComponent(nameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 455, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGap(18, 18, 18)
- .addComponent(updateNameButton)
- .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- .addComponent(descriptionLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addGroup(layout.createSequentialGroup()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addComponent(placeTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 456, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGap(18, 18, 18)
- .addComponent(updatePlaceButton))
- .addGroup(layout.createSequentialGroup()
- .addComponent(dateTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 457, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGap(18, 18, 18)
- .addComponent(updateDateButton))
- .addGroup(layout.createSequentialGroup()
- .addComponent(timeTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 455, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGap(18, 18, 18)
- .addComponent(updateTimeButton))
- .addGroup(layout.createSequentialGroup()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
- .addComponent(deleteMemoryButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
- .addComponent(backToAllMemoriesButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addGap(18, 18, 18)
- .addComponent(backToMenuButton, javax.swing.GroupLayout.PREFERRED_SIZE, 205, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addComponent(descriptionScrollPane, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 455, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGap(18, 18, 18)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(exitButton, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(updateDescriptionButton)))
- .addComponent(idTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 545, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGap(0, 22, Short.MAX_VALUE))))
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addContainerGap()
- .addComponent(detailsLabel)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(idLabel)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(idTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(nameLabel)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(nameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(updateNameButton))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(dateLabel)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(dateTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(updateDateButton))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(timeLabel)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(timeTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(updateTimeButton))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(placeLabel)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(placeTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(updatePlaceButton))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(descriptionLabel)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
- .addComponent(descriptionScrollPane)
- .addComponent(updateDescriptionButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- .addGap(18, 18, 18)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
- .addGroup(layout.createSequentialGroup()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(backToAllMemoriesButton)
- .addComponent(backToMenuButton))
- .addGap(18, 18, 18)
- .addComponent(deleteMemoryButton))
- .addComponent(exitButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- );
- pack();
- setLocationRelativeTo(null);
- }// </editor-fold>
- private void nameTextFieldActionPerformed(java.awt.event.ActionEvent evt)
- {
- // TODO add your handling code here:
- }
- private void idTextFieldActionPerformed(java.awt.event.ActionEvent evt)
- {
- // TODO add your handling code here:
- }
- private void placeTextFieldActionPerformed(java.awt.event.ActionEvent evt)
- {
- // TODO add your handling code here:
- }
- private void backToAllMemoriesButtonActionPerformed(java.awt.event.ActionEvent evt)
- {
- // TODO add your handling code here:
- this.setVisible(false);
- MemoryIndex memoryIndex = new MemoryIndex();
- memoryIndex.setVisible(true);
- }
- private void exitButtonActionPerformed(java.awt.event.ActionEvent evt)
- {
- // TODO add your handling code here:
- System.exit(0);
- }
- private void updateNameButtonActionPerformed(java.awt.event.ActionEvent evt)
- {
- // TODO add your handling code here:
- String driver="com.microsoft.sqlserver.jdbc.SQLServerDriver";
- String host = "jdbc:sqlserver://localhost:61271";
- String username = "sa";
- String password = "alvi";
- try
- {
- //connect database and fetch result
- Class.forName(driver);
- //fetch result
- String inputName = nameTextField.getText();
- //connect database and fetch result
- Connection connection = DriverManager.getConnection(host, username, password);
- Statement statement = connection.createStatement();
- statement.executeUpdate
- (
- " UPDATE diary.dbo.memoryAll " +
- " SET memoryName=' " +inputName+" ' "+
- " WHERE memoryID=" +this.memoryID
- );
- //close all
- statement.close();
- connection.close();
- }
- catch(SQLException sqlException)
- {
- sqlException.printStackTrace();
- JOptionPane.showMessageDialog
- (this,
- "Error code : "+sqlException.getErrorCode()+"\n"+
- "Error message : "+sqlException.getMessage()+"\n"+
- "SQL state : "+sqlException.getSQLState()+"\n"
- );
- }
- catch (ClassNotFoundException classNotFoundException)
- {
- classNotFoundException.printStackTrace();
- JOptionPane.showMessageDialog
- (this,
- "Error message : "+classNotFoundException.getMessage()+"\n"
- );
- }
- this.setVisible(false);
- MemoryIndex memoryIndex = new MemoryIndex();
- memoryIndex.setVisible(true);
- }
- private void deleteMemoryButtonActionPerformed(java.awt.event.ActionEvent evt)
- {
- // TODO add your handling code here:
- String driver="com.microsoft.sqlserver.jdbc.SQLServerDriver";
- String host = "jdbc:sqlserver://localhost:61271";
- String username = "sa";
- String password = "alvi";
- try
- {
- //connect database and fetch result
- Class.forName(driver);
- Connection connection = DriverManager.getConnection(host, username, password);
- Statement statement = connection.createStatement();
- statement.executeUpdate
- (
- "DELETE FROM diary.dbo.memoryAll " +
- "WHERE memoryID=" +this.memoryID
- );
- //close all
- statement.close();
- connection.close();
- }
- catch(SQLException sqlException)
- {
- JOptionPane.showMessageDialog
- (this,
- "Error code : "+sqlException.getErrorCode()+"\n"+
- "Error message : "+sqlException.getMessage()+"\n"+
- "SQL state : "+sqlException.getSQLState()+"\n"
- );
- }
- catch (ClassNotFoundException classNotFoundException)
- {
- classNotFoundException.printStackTrace();
- JOptionPane.showMessageDialog
- (this,
- "Error message : "+classNotFoundException.getMessage()+"\n"
- );
- }
- this.setVisible(false);
- MemoryIndex memoryIndex = new MemoryIndex();
- memoryIndex.setVisible(true);
- }
- private void updateTimeButtonActionPerformed(java.awt.event.ActionEvent evt)
- {
- // TODO add your handling code here:
- String driver="com.microsoft.sqlserver.jdbc.SQLServerDriver";
- String host = "jdbc:sqlserver://localhost:61271";
- String username = "sa";
- String password = "alvi";
- try
- {
- //convert string to util time
- String inputDate = timeTextField.getText();
- SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");
- java.util.Date utilDate = null;
- utilDate = formatter.parse(inputDate);
- //covert util date to sql date
- java.sql.Time sqlDate = new java.sql.Time(utilDate.getTime());
- //connect database and fetch result
- Class.forName(driver);
- Connection connection = DriverManager.getConnection(host, username, password);
- Statement statement = connection.createStatement();
- statement.executeUpdate
- (
- " UPDATE diary.dbo.memoryMoment " +
- " SET memoryMomentTime='"+sqlDate+"'"+
- " WHERE memoryID=" +this.memoryID
- );
- //close all
- statement.close();
- connection.close();
- }
- catch(SQLException sqlException)
- {
- sqlException.printStackTrace();
- JOptionPane.showMessageDialog
- (this,
- "Error code : "+sqlException.getErrorCode()+"\n"+
- "Error message : "+sqlException.getMessage()+"\n"+
- "SQL state : "+sqlException.getSQLState()+"\n"
- );
- }
- catch (ParseException parseException)
- {
- parseException.printStackTrace();
- JOptionPane.showMessageDialog
- (this,
- "Error message : "+parseException.getMessage()+"\n"+
- "Error offset : "+parseException.getErrorOffset()+"\n"
- );
- }
- catch (ClassNotFoundException classNotFoundException)
- {
- classNotFoundException.printStackTrace();
- JOptionPane.showMessageDialog
- (this,
- "Error message : "+classNotFoundException.getMessage()+"\n"
- );
- }
- this.setVisible(false);
- MemoryIndex memoryIndex = new MemoryIndex();
- memoryIndex.setVisible(true);
- }
- private void backToMenuButtonActionPerformed(java.awt.event.ActionEvent evt)
- {
- // TODO add your handling code here:
- this.setVisible(false);
- Menu menu = new Menu();
- menu.setVisible(true);
- }
- private void timeTextFieldActionPerformed(java.awt.event.ActionEvent evt)
- {
- // TODO add your handling code here:
- }
- private void updateDateButtonActionPerformed(java.awt.event.ActionEvent evt)
- {
- // TODO add your handling code here:
- String driver="com.microsoft.sqlserver.jdbc.SQLServerDriver";
- String host = "jdbc:sqlserver://localhost:61271";
- String username = "sa";
- String password = "alvi";
- try
- {
- //convert string to util date
- String inputDate = dateTextField.getText();
- SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
- java.util.Date utilDate = null;
- utilDate = formatter.parse(inputDate);
- //covert util date to sql date
- java.sql.Date sqlDate = new java.sql.Date(utilDate.getTime());
- //connect database and fetch
- Class.forName(driver);
- Connection connection = DriverManager.getConnection(host, username, password);
- Statement statement = connection.createStatement();
- statement.executeUpdate
- (
- " UPDATE diary.dbo.memoryMoment " +
- " SET memoryMomentDate='"+sqlDate+"'"+
- " WHERE memoryID=" +this.memoryID
- );
- //close all
- statement.close();
- connection.close();
- }
- catch(SQLException sqlException)
- {
- sqlException.printStackTrace();
- JOptionPane.showMessageDialog
- (this,
- "Error code : "+sqlException.getErrorCode()+"\n"+
- "Error message : "+sqlException.getMessage()+"\n"+
- "SQL state : "+sqlException.getSQLState()+"\n"
- );
- }
- catch (ParseException parseException)
- {
- parseException.printStackTrace();
- JOptionPane.showMessageDialog
- (this,
- "Error message : "+parseException.getMessage()+"\n"+
- "Error offset : "+parseException.getErrorOffset()+"\n"
- );
- }
- catch (ClassNotFoundException classNotFoundException)
- {
- classNotFoundException.printStackTrace();
- JOptionPane.showMessageDialog
- (this,
- "Error message : "+classNotFoundException.getMessage()+"\n"
- );
- }
- this.setVisible(false);
- MemoryIndex memoryIndex = new MemoryIndex();
- memoryIndex.setVisible(true);
- }
- private void dateTextFieldActionPerformed(java.awt.event.ActionEvent evt)
- {
- // TODO add your handling code here:
- }
- private void updateDescriptionButtonActionPerformed(java.awt.event.ActionEvent evt)
- {
- // TODO add your handling code here:
- String driver="com.microsoft.sqlserver.jdbc.SQLServerDriver";
- String host = "jdbc:sqlserver://localhost:61271";
- String username = "sa";
- String password = "alvi";
- try
- {
- //fetch result
- String inputDescription = descriptionTextArea.getText();
- //connect database and fetch result
- Class.forName(driver);
- Connection connection = DriverManager.getConnection(host, username, password);
- Statement statement = connection.createStatement();
- statement.executeUpdate
- (
- " UPDATE diary.dbo.memoryDescription " +
- " SET memoryDescriptionFull=' " +inputDescription+" ' "+
- " WHERE memoryID=" +this.memoryID
- );
- //close all
- statement.close();
- connection.close();
- }
- catch(SQLException sqlException)
- {
- sqlException.printStackTrace();
- JOptionPane.showMessageDialog
- (this,
- "Error code : "+sqlException.getErrorCode()+"\n"+
- "Error message : "+sqlException.getMessage()+"\n"+
- "SQL state : "+sqlException.getSQLState()+"\n"
- );
- }
- catch (ClassNotFoundException classNotFoundException)
- {
- classNotFoundException.printStackTrace();
- JOptionPane.showMessageDialog
- (this,
- "Error message : "+classNotFoundException.getMessage()+"\n"
- );
- }
- this.setVisible(false);
- MemoryIndex memoryIndex = new MemoryIndex();
- memoryIndex.setVisible(true);
- }
- private void updatePlaceButtonActionPerformed(java.awt.event.ActionEvent evt)
- {
- // TODO add your handling code here:
- String driver="com.microsoft.sqlserver.jdbc.SQLServerDriver";
- String host = "jdbc:sqlserver://localhost:61271";
- String username = "sa";
- String password = "alvi";
- try
- {
- //fetch result
- String inputPlace = placeTextField.getText();
- //connect database and fetch result
- Class.forName(driver);
- Connection connection = DriverManager.getConnection(host, username, password);
- Statement statement = connection.createStatement();
- statement.executeUpdate
- (
- " UPDATE diary.dbo.memoryPlace " +
- " SET memoryPlaceName=' " +inputPlace+" ' "+
- " WHERE memoryID=" +this.memoryID
- );
- //close all
- statement.close();
- connection.close();
- }
- catch(SQLException sqlException)
- {
- sqlException.printStackTrace();
- JOptionPane.showMessageDialog
- (this,
- "Error code : "+sqlException.getErrorCode()+"\n"+
- "Error message : "+sqlException.getMessage()+"\n"+
- "SQL state : "+sqlException.getSQLState()+"\n"
- );
- }
- catch (ClassNotFoundException classNotFoundException)
- {
- classNotFoundException.printStackTrace();
- JOptionPane.showMessageDialog
- (this,
- "Error message : "+classNotFoundException.getMessage()+"\n"
- );
- }
- this.setVisible(false);
- MemoryIndex memoryIndex = new MemoryIndex();
- memoryIndex.setVisible(true);
- }
- /**
- * @param args the command line arguments
- */
- public static void main(String args[])
- {
- /* Set the Nimbus look and feel */
- //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
- /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
- * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
- */
- try
- {
- for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels())
- {
- if ("Nimbus".equals(info.getName()))
- {
- javax.swing.UIManager.setLookAndFeel(info.getClassName());
- break;
- }
- }
- }
- catch (ClassNotFoundException ex)
- {
- java.util.logging.Logger.getLogger(MemoryDetails.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- }
- catch (InstantiationException ex)
- {
- java.util.logging.Logger.getLogger(MemoryDetails.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- }
- catch (IllegalAccessException ex)
- {
- java.util.logging.Logger.getLogger(MemoryDetails.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- }
- catch (javax.swing.UnsupportedLookAndFeelException ex)
- {
- java.util.logging.Logger.getLogger(MemoryDetails.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- }
- //</editor-fold>
- /* Create and display the form */
- java.awt.EventQueue.invokeLater(new Runnable()
- {
- public void run()
- {
- new MemoryDetails().setVisible(true);
- }
- });
- }
- // Variables declaration - do not modify
- private javax.swing.JButton backToAllMemoriesButton;
- private javax.swing.JButton backToMenuButton;
- private javax.swing.JLabel dateLabel;
- private javax.swing.JTextField dateTextField;
- private javax.swing.JButton deleteMemoryButton;
- private javax.swing.JLabel descriptionLabel;
- private javax.swing.JScrollPane descriptionScrollPane;
- private javax.swing.JTextArea descriptionTextArea;
- private javax.swing.JLabel detailsLabel;
- private javax.swing.JButton exitButton;
- private javax.swing.JLabel idLabel;
- private javax.swing.JTextField idTextField;
- private javax.swing.JLabel nameLabel;
- private javax.swing.JTextField nameTextField;
- private javax.swing.JLabel placeLabel;
- private javax.swing.JTextField placeTextField;
- private javax.swing.JLabel timeLabel;
- private javax.swing.JTextField timeTextField;
- private javax.swing.JButton updateDateButton;
- private javax.swing.JButton updateDescriptionButton;
- private javax.swing.JButton updateNameButton;
- private javax.swing.JButton updatePlaceButton;
- private javax.swing.JButton updateTimeButton;
- // End of variables declaration
- }
Add Comment
Please, Sign In to add comment