diff --git a/project01/bin/Product_management/res/coca_cola350ml.jpg b/project01/bin/Product_management/res/coca_cola350ml.jpg new file mode 100644 index 0000000..208dc74 Binary files /dev/null and b/project01/bin/Product_management/res/coca_cola350ml.jpg differ diff --git a/project01/bin/Product_management/res/coca_cola500ml.jpg b/project01/bin/Product_management/res/coca_cola500ml.jpg new file mode 100644 index 0000000..b0e0402 Binary files /dev/null and b/project01/bin/Product_management/res/coca_cola500ml.jpg differ diff --git a/project01/bin/Product_management/res/nuguri_bong.jpg b/project01/bin/Product_management/res/nuguri_bong.jpg new file mode 100644 index 0000000..752c193 Binary files /dev/null and b/project01/bin/Product_management/res/nuguri_bong.jpg differ diff --git a/project01/bin/Product_management/res/nuguri_cup.jpg b/project01/bin/Product_management/res/nuguri_cup.jpg new file mode 100644 index 0000000..9a4fef2 Binary files /dev/null and b/project01/bin/Product_management/res/nuguri_cup.jpg differ diff --git a/project01/bin/Product_management/res/search_icon1.png b/project01/bin/Product_management/res/search_icon1.png new file mode 100644 index 0000000..e3c221a Binary files /dev/null and b/project01/bin/Product_management/res/search_icon1.png differ diff --git a/project01/bin/Product_management/res/search_icon2.png b/project01/bin/Product_management/res/search_icon2.png new file mode 100644 index 0000000..d582254 Binary files /dev/null and b/project01/bin/Product_management/res/search_icon2.png differ diff --git a/project01/bin/Product_management/res/sinramyun_bong.jpg b/project01/bin/Product_management/res/sinramyun_bong.jpg new file mode 100644 index 0000000..a14dc86 Binary files /dev/null and b/project01/bin/Product_management/res/sinramyun_bong.jpg differ diff --git a/project01/bin/Product_management/res/sinramyun_cup.jpg b/project01/bin/Product_management/res/sinramyun_cup.jpg new file mode 100644 index 0000000..6a171c6 Binary files /dev/null and b/project01/bin/Product_management/res/sinramyun_cup.jpg differ diff --git a/project01/bin/Product_management/res/sunchips.jpg b/project01/bin/Product_management/res/sunchips.jpg new file mode 100644 index 0000000..772700d Binary files /dev/null and b/project01/bin/Product_management/res/sunchips.jpg differ diff --git a/project01/src/Product_management/Create_tables.java b/project01/src/Product_management/Create_tables.java new file mode 100644 index 0000000..5084dad --- /dev/null +++ b/project01/src/Product_management/Create_tables.java @@ -0,0 +1,80 @@ +package Product_management; + +import java.io.PrintWriter; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.SQLException; +import java.util.Properties; + +import com.zaxxer.hikari.HikariConfig; +import com.zaxxer.hikari.HikariDataSource; + +public class Create_tables { + + public Create_tables() { + // sus_01 Å×ÀÌºí »ý¼º°ú µ¿½Ã¿¡ sus_01Å×À̺íÀ» ±âº»À¸·ÎÇÑ sus_02 Å×ÀÌºí »ý¼ºÇØÁִ Ŭ·¡½º (try, catch·Î Å×À̺í Á¸Àç ¿©ºÎ¿¡ µû¸¥ ¸Þ¼¼Áö Ãâ·Â) + Properties props = new Properties(); + props.setProperty("dataSourceClassName", "oracle.jdbc.pool.OracleDataSource"); + props.setProperty("dataSource.url", "jdbc:oracle:thin:@localhost:1521/XEPDB1"); + props.setProperty("dataSource.user", "hr"); + props.setProperty("dataSource.password", "1234"); + props.put("dataSource.logWriter", new PrintWriter(System.out)); + + HikariConfig config = new HikariConfig(props); + HikariDataSource ds = new HikariDataSource(config); + + try { + // »õ·Î »ý¼ºµÇ´Â Å×À̺íÀÏ ½Ã (sus_02) + Connection conn = ds.getConnection(); + + + PreparedStatement pstmt = + conn.prepareStatement("CREATE TABLE sus_01 (\r\n" + + " product_name VARCHAR2(25)\r\n" + + " CONSTRAINT product_name_pk PRIMARY KEY,\r\n" + + " commodity_price NUMBER(6)\r\n" + + " CONSTRAINT commodity_price_nn NOT NULL,\r\n" + + " manufacturer VARCHAR2(25)\r\n" + + " CONSTRAINT manufacturer_nn NOT NULL,\r\n" + + " nutrition_information VARCHAR2(15)\r\n" + + " CONSTRAINT nutinfo_nn NOT NULL,\r\n" + + " product_image VARCHAR2(30)\r\n" + + " CONSTRAINT product_image_nn NOT NULL\r\n" + + ")"); + + int row = pstmt.executeUpdate(); + + System.out.printf("%dÇàÀÌ ¾÷µ¥ÀÌÆ® µÇ¾ú½À´Ï´Ù.\n", row); + System.out.println("sus_01 Å×ÀÌºí »ý¼º ¿Ï·á"); + + if (pstmt != null) pstmt.close(); + if (conn != null) conn.close(); + + } catch (SQLException e) { + // ÀÌ¹Ì »ý¼ºµÈ Å×À̺íÀÌ Á¸ÀçÇÒ ½Ã (sus_01) + System.out.println("sus_01 Å×À̺í Á¸Àç(»ý¼º x)"); + } + + try { + // »õ·Î »ý¼ºµÇ´Â Å×À̺íÀÏ ½Ã (sus_02) + Connection conn = ds.getConnection(); + + + PreparedStatement pstmt = + conn.prepareStatement("CREATE TABLE sus_02 AS SELECT * FROM sus_01"); + + int row = pstmt.executeUpdate(); + + System.out.printf("%dÇàÀÌ ¾÷µ¥ÀÌÆ® µÇ¾ú½À´Ï´Ù.\n", row); + System.out.println("sus_02 Å×ÀÌºí »ý¼º ¿Ï·á"); + + if (pstmt != null) pstmt.close(); + if (conn != null) conn.close(); + + } catch (SQLException e) { + // ÀÌ¹Ì »ý¼ºµÈ Å×À̺íÀÌ Á¸ÀçÇÒ ½Ã (sus_02) + System.out.println("sus_02 Å×À̺í Á¸Àç(»ý¼º x)"); + } + + } +} diff --git a/project01/src/Product_management/Main_frame.java b/project01/src/Product_management/Main_frame.java new file mode 100644 index 0000000..455345e --- /dev/null +++ b/project01/src/Product_management/Main_frame.java @@ -0,0 +1,191 @@ +package Product_management; + +import java.awt.Color; +import java.awt.Cursor; +import java.awt.EventQueue; +import java.awt.Font; +import java.awt.Image; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; + +import javax.swing.ImageIcon; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.SwingConstants; +import javax.swing.border.LineBorder; +import javax.swing.JTextField; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; + +public class Main_frame extends JFrame { + + private Image search_icon1 = new ImageIcon(Main_frame.class.getResource("res/search_icon1.png")).getImage().getScaledInstance(32, 32, Image.SCALE_SMOOTH); + private Image search_icon2 = new ImageIcon(Main_frame.class.getResource("res/search_icon2.png")).getImage().getScaledInstance(32, 32, Image.SCALE_SMOOTH); + + private JPanel contentPane; + private JTextField search_textField; + + public static void main(String[] args) { + EventQueue.invokeLater(new Runnable() { + public void run() { + try { + Main_frame frame = new Main_frame(); + frame.setVisible(true); + } catch (Exception e) { + e.printStackTrace(); + } + } + }); + } + + public Main_frame() { + // ¸ÞÀÎ ÇÁ·¹ÀÓ ½ÇÇà ½Ã¸¶´Ù Å×ÀÌºí »ý¼º, »óǰÁ¤º¸ ÀÚµ¿ °ü¸® ±â´ÉÀÌ ½ÇÇàµÇ°Ô ±¸Çö + // Ãß°¡ÀûÀÎ ±â´ÉÀ¸·Î »óǰ¸í ÀÔ·Â ½Ã »óǰ À̹ÌÁö¿Í Á¤º¸°¡ Ãâ·ÂµÇ´Â ±â´É ±¸Çö + new Create_tables(); + new Outo_management(); + + setUndecorated(true); + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + setBounds(360, 150, 1200, 800 + ); + contentPane = new JPanel(); + contentPane.setBackground(Color.GRAY); + contentPane.setBorder(new LineBorder(Color.BLACK, 2)); + setContentPane(contentPane); + contentPane.setLayout(null); + + // ±âÁ¸ ÃÖ¼ÒÈ­, È®´ë, ´Ý±â âÀ» ¾ø¾Ö°í ½ÉÇÃÇÏ°Ô ´Ý±â ¹öư¸¸ ¸¸µé¾î ³Ö¾î³ð + JLabel lblX = new + JLabel("X"); + lblX.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + if (JOptionPane.showConfirmDialog(null, "¾îÇø®ÄÉÀ̼ÇÀ» Á¾·áÇϽðڽÀ´Ï±î?", "Confirmation", JOptionPane.YES_NO_OPTION) == 0) { + Main_frame.this.dispose(); + } + } + @Override + public void mouseEntered(MouseEvent e) { + lblX.setForeground(Color.DARK_GRAY); + Cursor cursor = new Cursor(Cursor.HAND_CURSOR); + setCursor(cursor); + } + @Override + public void mouseExited(MouseEvent e) { + lblX.setForeground(Color.WHITE); + Cursor normalCursor = new Cursor(Cursor.DEFAULT_CURSOR); + setCursor(normalCursor); + } + @Override + public void mousePressed(MouseEvent e) { + lblX.setForeground(Color.WHITE); + } + @Override + public void mouseReleased(MouseEvent e) { + lblX.setForeground(Color.DARK_GRAY); + } + + }); + lblX.setForeground(Color.WHITE); + lblX.setFont(new Font("Comic Sans MS", Font.BOLD, 14)); + lblX.setHorizontalAlignment(SwingConstants.CENTER); + lblX.setBounds(1180, 0, 20, 20); + contentPane.add(lblX); + + JLabel lblMainLabel = new JLabel("\uC0C1\uD488\uAD00\uB9AC"); + lblMainLabel.setHorizontalAlignment(SwingConstants.CENTER); + lblMainLabel.setFont(new Font("¸¼Àº °íµñ", Font.BOLD, 45)); + lblMainLabel.setForeground(Color.WHITE); + lblMainLabel.setBounds(12, 10, 1176, 107); + contentPane.add(lblMainLabel); + + JLabel lblSearchProduct = new JLabel("\uC0C1\uD488 \uAC80\uC0C9"); + lblSearchProduct.setHorizontalAlignment(SwingConstants.LEFT); + lblSearchProduct.setFont(new Font("¸¼Àº °íµñ", Font.BOLD, 30)); + lblSearchProduct.setForeground(Color.WHITE); + lblSearchProduct.setBounds(195, 166, 131, 42); + contentPane.add(lblSearchProduct); + + JLabel lblProduct_imageLabel = new JLabel(""); + lblProduct_imageLabel.setBounds(498, 286, 224, 267); + contentPane.add(lblProduct_imageLabel); + + JLabel lblSearchResult = new JLabel(""); + lblSearchResult.setForeground(Color.WHITE); + lblSearchResult.setFont(new Font("¸¼Àº °íµñ", Font.PLAIN, 14)); + lblSearchResult.setHorizontalAlignment(SwingConstants.LEFT); + lblSearchResult.setBounds(195, 626, 841, 48); + contentPane.add(lblSearchResult); + + // °Ë»ö¹öư Ŭ¸¯ÀÌ ¾Æ´Ñ enterŰ ÀÔ·ÂÀ¸·Îµµ »ç¿ë °¡´ÉÇÏ°Ô ketPressedÃß°¡ + search_textField = new JTextField(); + search_textField.addKeyListener(new KeyAdapter() { + @Override + public void keyPressed(KeyEvent e) { + int key = e.getKeyCode(); + if (key == KeyEvent.VK_ENTER) { + String product_name = search_textField.getText(); + if (product_name.equals("")) { + // »óǰ¸í ¹Ì ÀÔ·Â ½Ã Ãâ·ÂµÇ´Â ¸Þ¼¼Áö (¿£ÅÍŰ) + lblSearchResult.setText("»óǰ¸íÀ» ÀÔ·ÂÇØÁÖ¼¼¿ä."); + } else if(new Search_with_product_name().info(product_name).equals("")) { + // »óǰ¸í À߸ø ÀÔ·Â ½Ã Ãâ·ÂµÇ´Â ¸Þ¼¼Áö (¿£ÅÍŰ) + lblSearchResult.setText("Á¸ÀçÇÏÁö ¾Ê´Â »óǰ¸íÀÔ´Ï´Ù."); + } else { + // »óǰ¸íÀÌ Á¦´ë·Î ÀԷµǾúÀ» ½Ã Ãâ·ÂµÇ´Â ¸Þ¼¼Áö¿Í À̹ÌÁö (¿£ÅÍŰ) + lblProduct_imageLabel.setIcon(new ImageIcon(new ImageIcon(Main_frame.class.getResource("res/" + product_name + ".jpg")).getImage().getScaledInstance(224, 267, Image.SCALE_SMOOTH))); + lblSearchResult.setText(new Search_with_product_name().info(product_name)); + } + } + } + }); + search_textField.setBounds(338, 173, 161, 32); + contentPane.add(search_textField); + search_textField.setColumns(10); + + // °Ë»ö¹öư Ŭ¸¯ ½Ã ¹ßµ¿µÇ´Â ¾×¼Ç ¸®½º³Ê Ãß°¡ + JLabel lblSearchLabel = new JLabel(""); + lblSearchLabel.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + String product_name = search_textField.getText(); + // »óǰ¸í ¹Ì ÀÔ·Â ½Ã Ãâ·ÂµÇ´Â ¸Þ¼¼Áö (°Ë»ö¹öư) + if (product_name.equals("")) { + lblSearchResult.setText("»óǰ¸íÀ» ÀÔ·ÂÇØÁÖ¼¼¿ä."); + } else if(new Search_with_product_name().info(product_name).equals("")) { + // »óǰ¸í À߸ø ÀÔ·Â ½Ã Ãâ·ÂµÇ´Â ¸Þ¼¼Áö (¿£ÅÍŰ) + lblSearchResult.setText("Á¸ÀçÇÏÁö ¾Ê´Â »óǰ¸íÀÔ´Ï´Ù."); + } else { + // »óǰ¸íÀÌ Á¦´ë·Î ÀԷµǾúÀ» ½Ã Ãâ·ÂµÇ´Â ¸Þ¼¼Áö¿Í À̹ÌÁö (°Ë»ö¹öư) + lblProduct_imageLabel.setIcon(new ImageIcon(new ImageIcon(Main_frame.class.getResource("res/" + product_name + ".jpg")).getImage().getScaledInstance(224, 267, Image.SCALE_SMOOTH))); + lblSearchResult.setText(new Search_with_product_name().info(product_name)); + } + } + @Override + public void mouseEntered(MouseEvent e) { + Cursor cursor = new Cursor(Cursor.HAND_CURSOR); + setCursor(cursor); + lblSearchLabel.setIcon(new ImageIcon(search_icon2)); + } + @Override + public void mouseExited(MouseEvent e) { + Cursor normalCursor = new Cursor(Cursor.DEFAULT_CURSOR); + setCursor(normalCursor); + lblSearchLabel.setIcon(new ImageIcon(search_icon1)); + } + @Override + public void mousePressed(MouseEvent e) { + lblSearchLabel.setIcon(new ImageIcon(search_icon1)); + } + @Override + public void mouseReleased(MouseEvent e) { + lblSearchLabel.setIcon(new ImageIcon(search_icon2)); + } + }); + lblSearchLabel.setBounds(498, 173, 32, 32); + contentPane.add(lblSearchLabel); + lblSearchLabel.setIcon(new ImageIcon(search_icon1)); + } +} diff --git a/project01/src/Product_management/Outo_management.java b/project01/src/Product_management/Outo_management.java new file mode 100644 index 0000000..49719dd --- /dev/null +++ b/project01/src/Product_management/Outo_management.java @@ -0,0 +1,57 @@ +package Product_management; + +import java.io.PrintWriter; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.SQLException; +import java.util.Properties; + +import com.zaxxer.hikari.HikariConfig; +import com.zaxxer.hikari.HikariDataSource; + +public class Outo_management { + + public Outo_management() { + // sus_02ÀÇ »óǰ¸íÀÌ sus_01ÀÇ »óǰ¸í°ú °°À» ¶§´Â °»½Å(update)À» ´Ù¸¥ ¶§¿¡´Â Ãß°¡(insert)¸¦ ÇØÁִ Ŭ·¡½º (»óǰÁ¤º¸ ÀÚµ¿°ü¸®) + Properties props = new Properties(); + props.setProperty("dataSourceClassName", "oracle.jdbc.pool.OracleDataSource"); + props.setProperty("dataSource.url", "jdbc:oracle:thin:@localhost:1521/XEPDB1"); + props.setProperty("dataSource.user", "hr"); + props.setProperty("dataSource.password", "1234"); + props.put("dataSource.logWriter", new PrintWriter(System.out)); + + HikariConfig config = new HikariConfig(props); + HikariDataSource ds = new HikariDataSource(config); + + try { + Connection conn = ds.getConnection(); + + PreparedStatement pstmt = + // MERGE INTO Äõ¸®¹®À» Ȱ¿ëÇÏ¿©, »óǰÀÌ sus_01¿¡ ÀÖ°í, sus_02¿¡ ¾øÀ» ‹š Á¤º¸¸¦ Ãß°¡ÇÏ´Â ±â´É°ú + // »óǰÀÌ sus_01°ú sus_02¿¡ ¸ðµÎ Á¸ÀçÇÒ ¶§, Á¤º¸¸¦ °»½ÅÇÏ´Â ±â´ÉÀ» Çѹø¿¡ ±¸Çö + conn.prepareStatement("MERGE INTO sus_02 a\r\n" + + " USING sus_01 b\r\n" + + " ON (b.product_name = a.product_name)\r\n" + + " WHEN MATCHED THEN\r\n" + + " UPDATE SET\r\n" + + " a.commodity_price = b.commodity_price,\r\n" + + " a.manufacturer = b.manufacturer,\r\n" + + " a.nutrition_information = b.nutrition_information,\r\n" + + " a.product_image = b.product_image\r\n" + + " WHEN NOT MATCHED THEN\r\n" + + " INSERT (a.product_name, a.commodity_price, a.manufacturer, a.nutrition_information, a.product_image)\r\n" + + " VALUES (b.product_name, b.commodity_price, b.manufacturer, b.nutrition_information, b.product_image)"); + + int row = pstmt.executeUpdate(); + + System.out.printf("sus_02Á¡Æ÷ »óǰÁ¤º¸ ÀÚµ¿ ¾÷µ¥ÀÌÆ® ¿Ï·á"); + + if (pstmt != null) pstmt.close(); + if (conn != null) conn.close(); + + } catch (SQLException e) { + e.printStackTrace(); + } + } + +} diff --git a/project01/src/Product_management/Search_with_product_name.java b/project01/src/Product_management/Search_with_product_name.java new file mode 100644 index 0000000..7a1901e --- /dev/null +++ b/project01/src/Product_management/Search_with_product_name.java @@ -0,0 +1,55 @@ +package Product_management; + +import java.io.PrintWriter; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.Properties; + +import com.zaxxer.hikari.HikariConfig; +import com.zaxxer.hikari.HikariDataSource; + +public class Search_with_product_name { + + // »óǰ¸íÀ¸·Î °Ë»öÇßÀ» ¶§ °Ë»ö °ªÀ» ¸®ÅÏÇØÁ٠Ŭ·¡½º + public String info(String product_name) { + String information = ""; + Properties props = new Properties(); + props.setProperty("dataSourceClassName", "oracle.jdbc.pool.OracleDataSource"); + props.setProperty("dataSource.url", "jdbc:oracle:thin:@localhost:1521/XEPDB1"); + props.setProperty("dataSource.user", "hr"); + props.setProperty("dataSource.password", "1234"); + props.put("dataSource.logWriter", new PrintWriter(System.out)); + + HikariConfig config = new HikariConfig(props); + HikariDataSource ds = new HikariDataSource(config); + + try { + Connection conn = ds.getConnection(); + + // TO_CHAR¸¦ ÀÌ¿ëÇØ ±âÁ¸¿¡ ±×³É ¼ýÀÚ·Î µé¾î°¡ÀÖ´ø »óǰ°¡°ÝÀ» Çѱ¹½ÄÀ¸·Î õ´ÜÀ§ , Ãß°¡¿Í °¡°ÝµÚ¿¡ ¿ø´ÜÀ§¸¦ ºÙÀÌ°Ô Ãâ·Â + String sql = "SELECT product_name, TO_CHAR(commodity_price,'9,999,999L') as \"commodity_price\", manufacturer, nutrition_information, product_image FROM sus_01 WHERE product_name = ?"; + + PreparedStatement pstmt = + conn.prepareStatement(sql); + + pstmt.setString(1, product_name); + + ResultSet rs = pstmt.executeQuery(); + while (rs.next()) { + information = String.format("[»óǰ¸í]: %s [°¡°Ý]:%s [Á¦Á¶»ç]: %s [¿µ¾çÁ¤º¸]: %s", rs.getString("product_name"), rs.getString("commodity_price"), rs.getString("manufacturer"), rs.getString("nutrition_information")); + } + + rs.close(); + pstmt.close(); + conn.close(); + + } catch (SQLException e) { + e.printStackTrace(); + } + return information; + + } + +} diff --git a/project01/src/Product_management/res/coca_cola350ml.jpg b/project01/src/Product_management/res/coca_cola350ml.jpg new file mode 100644 index 0000000..208dc74 Binary files /dev/null and b/project01/src/Product_management/res/coca_cola350ml.jpg differ diff --git a/project01/src/Product_management/res/coca_cola500ml.jpg b/project01/src/Product_management/res/coca_cola500ml.jpg new file mode 100644 index 0000000..b0e0402 Binary files /dev/null and b/project01/src/Product_management/res/coca_cola500ml.jpg differ diff --git a/project01/src/Product_management/res/nuguri_bong.jpg b/project01/src/Product_management/res/nuguri_bong.jpg new file mode 100644 index 0000000..752c193 Binary files /dev/null and b/project01/src/Product_management/res/nuguri_bong.jpg differ diff --git a/project01/src/Product_management/res/nuguri_cup.jpg b/project01/src/Product_management/res/nuguri_cup.jpg new file mode 100644 index 0000000..9a4fef2 Binary files /dev/null and b/project01/src/Product_management/res/nuguri_cup.jpg differ diff --git a/project01/src/Product_management/res/search_icon1.png b/project01/src/Product_management/res/search_icon1.png new file mode 100644 index 0000000..e3c221a Binary files /dev/null and b/project01/src/Product_management/res/search_icon1.png differ diff --git a/project01/src/Product_management/res/search_icon2.png b/project01/src/Product_management/res/search_icon2.png new file mode 100644 index 0000000..d582254 Binary files /dev/null and b/project01/src/Product_management/res/search_icon2.png differ diff --git a/project01/src/Product_management/res/sinramyun_bong.jpg b/project01/src/Product_management/res/sinramyun_bong.jpg new file mode 100644 index 0000000..a14dc86 Binary files /dev/null and b/project01/src/Product_management/res/sinramyun_bong.jpg differ diff --git a/project01/src/Product_management/res/sinramyun_cup.jpg b/project01/src/Product_management/res/sinramyun_cup.jpg new file mode 100644 index 0000000..6a171c6 Binary files /dev/null and b/project01/src/Product_management/res/sinramyun_cup.jpg differ diff --git a/project01/src/Product_management/res/sunchips.jpg b/project01/src/Product_management/res/sunchips.jpg new file mode 100644 index 0000000..772700d Binary files /dev/null and b/project01/src/Product_management/res/sunchips.jpg differ