From 5731d45e17ec4dbf8bc911b609c40d4afb04f06f Mon Sep 17 00:00:00 2001 From: dch02 Date: Sat, 15 May 2021 13:24:55 +0900 Subject: [PATCH] =?UTF-8?q?=EA=B3=BC=EC=A0=9C=ED=8F=89=EA=B0=80=20?= =?UTF-8?q?=EC=B5=9C=EC=A2=85=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Product_management/Add_product.java | 58 ++++ .../Product_management/Delete_product.java | 52 ++++ .../src/Product_management/Main_frame.java | 250 ++++++++++++++++-- .../Search_with_product_name.java | 121 ++++++++- 4 files changed, 458 insertions(+), 23 deletions(-) create mode 100644 project01/src/Product_management/Add_product.java create mode 100644 project01/src/Product_management/Delete_product.java diff --git a/project01/src/Product_management/Add_product.java b/project01/src/Product_management/Add_product.java new file mode 100644 index 0000000..e2eea3b --- /dev/null +++ b/project01/src/Product_management/Add_product.java @@ -0,0 +1,58 @@ +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 Add_product { + + // ÀÔ·ÂµÈ °ªÀ¸·Î »óǰÀ» Ãß°¡½ÃŰ´Â Ŭ·¡½º (»óǰ¸íÀº PK·Î ¼³Á¤Çسù±â‹š¹®¿¡ Áߺ¹µÉ °¡´É¼ºx) + public String Add(String p_name, int c_price, String manufacturer, String n_info) { + 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 = + conn.prepareStatement("INSERT INTO sus_01 VALUES(?, ?, ?, ?, ?)"); + + pstmt.setString(1, p_name); + pstmt.setInt(2, c_price); + pstmt.setString(3, manufacturer); + pstmt.setString(4, n_info); + pstmt.setString(5, p_name + ".jpg"); + + + int row = pstmt.executeUpdate(); + + System.out.printf("%dÇàÀÌ ¾÷µ¥ÀÌÆ® µÇ¾ú½À´Ï´Ù.\n", row); + System.out.println("»óǰÀÌ Ãß°¡µÇ¾ú½À´Ï´Ù."); + + if (pstmt != null) pstmt.close(); + if (conn != null) conn.close(); + + // »óǰ Ãß°¡¿¡ ¼º°øÇßÀ» ‹š + return "s"; + } catch (SQLException e) { + e.printStackTrace(); + System.out.println("»óǰ Ãß°¡¿¡ ½ÇÆÐÇß½À´Ï´Ù."); + // »óǰ Ãß°¡¿¡ ½ÇÆÐÇßÀ» ¶§ + return "f"; + } + + } + +} diff --git a/project01/src/Product_management/Delete_product.java b/project01/src/Product_management/Delete_product.java new file mode 100644 index 0000000..d474223 --- /dev/null +++ b/project01/src/Product_management/Delete_product.java @@ -0,0 +1,52 @@ +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 Delete_product { + + // »óǰ¸íÀ¸·Î »èÁ¦ÇÏ°í ½ÍÀº »óǰÀ» »èÁ¦Çϴ Ŭ·¡½º + public String Delete(String p_name) { + 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 = + conn.prepareStatement("DELETE FROM sus_01 WHERE product_name = ?"); + + pstmt.setString(1, p_name); + + int row = pstmt.executeUpdate(); + + System.out.printf("%dÇàÀÌ ¾÷µ¥ÀÌÆ® µÇ¾ú½À´Ï´Ù.\n", row); + System.out.println("»óǰÀÌ »èÁ¦µÇ¾ú½À´Ï´Ù."); + + if (pstmt != null) pstmt.close(); + if (conn != null) conn.close(); + + // »óǰ »èÁ¦¿¡ ¼º°øÇßÀ» ‹š + return "s"; + } catch (SQLException e) { + e.printStackTrace(); + System.out.println("»óǰ »èÁ¦¿¡ ½ÇÆÐÇß½À´Ï´Ù."); + // »óǰ »èÁ¦¿¡ ½ÇÆÐÇßÀ» ¶§ + return "f"; + } + } + +} diff --git a/project01/src/Product_management/Main_frame.java b/project01/src/Product_management/Main_frame.java index 455345e..83b988d 100644 --- a/project01/src/Product_management/Main_frame.java +++ b/project01/src/Product_management/Main_frame.java @@ -26,6 +26,11 @@ public class Main_frame extends JFrame { private JPanel contentPane; private JTextField search_textField; + private JTextField AddP_name; + private JTextField AddC_price; + private JTextField AddManufacturer; + private JTextField AddN_info; + private JTextField DP_name; public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { @@ -105,19 +110,40 @@ public void mouseReleased(MouseEvent e) { lblSearchProduct.setHorizontalAlignment(SwingConstants.LEFT); lblSearchProduct.setFont(new Font("¸¼Àº °íµñ", Font.BOLD, 30)); lblSearchProduct.setForeground(Color.WHITE); - lblSearchProduct.setBounds(195, 166, 131, 42); + lblSearchProduct.setBounds(113, 164, 131, 42); contentPane.add(lblSearchProduct); JLabel lblProduct_imageLabel = new JLabel(""); - lblProduct_imageLabel.setBounds(498, 286, 224, 267); + lblProduct_imageLabel.setBounds(171, 223, 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); + JLabel lblProduct_nameResult = new JLabel(""); + lblProduct_nameResult.setForeground(Color.WHITE); + lblProduct_nameResult.setFont(new Font("¸¼Àº °íµñ", Font.PLAIN, 14)); + lblProduct_nameResult.setHorizontalAlignment(SwingConstants.LEFT); + lblProduct_nameResult.setBounds(98, 510, 379, 48); + contentPane.add(lblProduct_nameResult); + + JLabel lblCommodity_priceResult = new JLabel(""); + lblCommodity_priceResult.setHorizontalAlignment(SwingConstants.LEFT); + lblCommodity_priceResult.setForeground(Color.WHITE); + lblCommodity_priceResult.setFont(new Font("¸¼Àº °íµñ", Font.PLAIN, 14)); + lblCommodity_priceResult.setBounds(98, 580, 379, 48); + contentPane.add(lblCommodity_priceResult); + + JLabel lblManufacturerResult = new JLabel(""); + lblManufacturerResult.setHorizontalAlignment(SwingConstants.LEFT); + lblManufacturerResult.setForeground(Color.WHITE); + lblManufacturerResult.setFont(new Font("¸¼Àº °íµñ", Font.PLAIN, 14)); + lblManufacturerResult.setBounds(98, 650, 379, 48); + contentPane.add(lblManufacturerResult); + + JLabel lblNutrition_informationResult = new JLabel(""); + lblNutrition_informationResult.setHorizontalAlignment(SwingConstants.LEFT); + lblNutrition_informationResult.setForeground(Color.WHITE); + lblNutrition_informationResult.setFont(new Font("¸¼Àº °íµñ", Font.PLAIN, 14)); + lblNutrition_informationResult.setBounds(98, 720, 379, 48); + contentPane.add(lblNutrition_informationResult); // °Ë»ö¹öư Ŭ¸¯ÀÌ ¾Æ´Ñ enterŰ ÀÔ·ÂÀ¸·Îµµ »ç¿ë °¡´ÉÇÏ°Ô ketPressedÃß°¡ search_textField = new JTextField(); @@ -129,19 +155,24 @@ public void keyPressed(KeyEvent e) { String product_name = search_textField.getText(); if (product_name.equals("")) { // »óǰ¸í ¹Ì ÀÔ·Â ½Ã Ãâ·ÂµÇ´Â ¸Þ¼¼Áö (¿£ÅÍŰ) - lblSearchResult.setText("»óǰ¸íÀ» ÀÔ·ÂÇØÁÖ¼¼¿ä."); - } else if(new Search_with_product_name().info(product_name).equals("")) { + lblProduct_nameResult.setText("»óǰ¸íÀ» ÀÔ·ÂÇØÁÖ¼¼¿ä."); + } else if(new Search_with_product_name().product_name(product_name).equals("")) { // »óǰ¸í À߸ø ÀÔ·Â ½Ã Ãâ·ÂµÇ´Â ¸Þ¼¼Áö (¿£ÅÍŰ) - lblSearchResult.setText("Á¸ÀçÇÏÁö ¾Ê´Â »óǰ¸íÀÔ´Ï´Ù."); + lblProduct_nameResult.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)); + lblProduct_nameResult.setText(new Search_with_product_name().product_name(product_name)); + lblCommodity_priceResult.setText(new Search_with_product_name().commodity_price(product_name)); + lblManufacturerResult.setText(new Search_with_product_name().manufacturer(product_name)); + lblNutrition_informationResult.setText(new Search_with_product_name().nutrition_information(product_name)); } - } + search_textField.setText(""); + } + } }); - search_textField.setBounds(338, 173, 161, 32); + search_textField.setBounds(256, 171, 161, 32); contentPane.add(search_textField); search_textField.setColumns(10); @@ -153,15 +184,20 @@ 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("")) { + // »óǰ¸í ¹Ì ÀÔ·Â ½Ã Ãâ·ÂµÇ´Â ¸Þ¼¼Áö (¿£ÅÍŰ) + lblProduct_nameResult.setText("»óǰ¸íÀ» ÀÔ·ÂÇØÁÖ¼¼¿ä."); + } else if(new Search_with_product_name().product_name(product_name).equals("")) { // »óǰ¸í À߸ø ÀÔ·Â ½Ã Ãâ·ÂµÇ´Â ¸Þ¼¼Áö (¿£ÅÍŰ) - lblSearchResult.setText("Á¸ÀçÇÏÁö ¾Ê´Â »óǰ¸íÀÔ´Ï´Ù."); + lblProduct_nameResult.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)); + lblProduct_nameResult.setText(new Search_with_product_name().product_name(product_name)); + lblCommodity_priceResult.setText(new Search_with_product_name().commodity_price(product_name)); + lblManufacturerResult.setText(new Search_with_product_name().manufacturer(product_name)); + lblNutrition_informationResult.setText(new Search_with_product_name().nutrition_information(product_name)); } + search_textField.setText(""); } @Override public void mouseEntered(MouseEvent e) { @@ -184,8 +220,182 @@ public void mouseReleased(MouseEvent e) { lblSearchLabel.setIcon(new ImageIcon(search_icon2)); } }); - lblSearchLabel.setBounds(498, 173, 32, 32); + lblSearchLabel.setBounds(416, 171, 32, 32); contentPane.add(lblSearchLabel); lblSearchLabel.setIcon(new ImageIcon(search_icon1)); + + JPanel panel = new JPanel(); + panel.setBackground(new Color(105, 105, 105)); + panel.setBounds(590, 127, 10, 673); + contentPane.add(panel); + + JLabel lblAddProduct = new JLabel("\uC0C1\uD488 \uCD94\uAC00"); + lblAddProduct.setHorizontalAlignment(SwingConstants.LEFT); + lblAddProduct.setForeground(Color.WHITE); + lblAddProduct.setFont(new Font("¸¼Àº °íµñ", Font.BOLD, 30)); + lblAddProduct.setBounds(844, 164, 131, 42); + contentPane.add(lblAddProduct); + + JPanel panel_1 = new JPanel(); + panel_1.setBackground(new Color(105, 105, 105)); + panel_1.setBounds(0, 123, 1200, 10); + contentPane.add(panel_1); + + JPanel panel_2 = new JPanel(); + panel_2.setBackground(new Color(192, 192, 192)); + panel_2.setBounds(0, 0, 1200, 125); + contentPane.add(panel_2); + + JLabel lblDeleteProduct = new JLabel("\uC0C1\uD488 \uC0AD\uC81C"); + lblDeleteProduct.setHorizontalAlignment(SwingConstants.LEFT); + lblDeleteProduct.setForeground(Color.WHITE); + lblDeleteProduct.setFont(new Font("¸¼Àº °íµñ", Font.BOLD, 30)); + lblDeleteProduct.setBounds(844, 532, 131, 42); + contentPane.add(lblDeleteProduct); + + JLabel lblAddPName = new JLabel("\uC0C1\uD488\uBA85"); + lblAddPName.setForeground(new Color(255, 255, 255)); + lblAddPName.setFont(new Font("¸¼Àº °íµñ", Font.BOLD, 20)); + lblAddPName.setBounds(723, 234, 60, 32); + contentPane.add(lblAddPName); + + JLabel lblAddC_price = new JLabel("\uC0C1\uD488\uAC00\uACA9"); + lblAddC_price.setForeground(Color.WHITE); + lblAddC_price.setFont(new Font("¸¼Àº °íµñ", Font.BOLD, 20)); + lblAddC_price.setBounds(723, 294, 86, 32); + contentPane.add(lblAddC_price); + + JLabel lblAddManufacturer = new JLabel("\uC81C\uC870\uC0AC"); + lblAddManufacturer.setForeground(Color.WHITE); + lblAddManufacturer.setFont(new Font("¸¼Àº °íµñ", Font.BOLD, 20)); + lblAddManufacturer.setBounds(723, 354, 60, 32); + contentPane.add(lblAddManufacturer); + + JLabel lblAddN_info = new JLabel("\uC601\uC591\uC815\uBCF4"); + lblAddN_info.setForeground(Color.WHITE); + lblAddN_info.setFont(new Font("¸¼Àº °íµñ", Font.BOLD, 20)); + lblAddN_info.setBounds(723, 414, 86, 32); + contentPane.add(lblAddN_info); + + AddP_name = new JTextField(); + AddP_name.setBounds(821, 241, 216, 21); + contentPane.add(AddP_name); + AddP_name.setColumns(10); + + AddC_price = new JTextField(); + AddC_price.setColumns(10); + AddC_price.setBounds(821, 301, 216, 21); + contentPane.add(AddC_price); + + AddManufacturer = new JTextField(); + AddManufacturer.setColumns(10); + AddManufacturer.setBounds(821, 360, 216, 21); + contentPane.add(AddManufacturer); + + AddN_info = new JTextField(); + AddN_info.setColumns(10); + AddN_info.setBounds(821, 420, 216, 21); + contentPane.add(AddN_info); + + JLabel lblAddBtn = new JLabel("\uCD94\uAC00"); + lblAddBtn.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + if (new Add_product().Add(AddP_name.getText(), Integer.parseInt(AddC_price.getText()), AddManufacturer.getText(), AddN_info.getText()).equals("s")) { + // »õ·Î sus_01¿¡ Á¤º¸°¡ Ãß°¡µÇ¾ú±â¶§¹®¿¡ ÀÚµ¿È­ ÀÛ¾÷ ÇÊ¿ä + new Outo_management(); + // »óǰ Ãß°¡¿¡ ¼º°ø + JOptionPane.showMessageDialog(null, "[" + AddP_name.getText() + "] »óǰÀ» ¼º°øÀûÀ¸·Î Ãß°¡Çß½À´Ï´Ù."); + } else { + // »óǰ Ãß°¡¿¡ ½ÇÆÐ + JOptionPane.showMessageDialog(null, "[" + AddP_name.getText() + "] »óǰ Ãß°¡¿¡ ½ÇÆÐÇß½À´Ï´Ù."); + } + AddP_name.setText(""); + AddC_price.setText(""); + AddManufacturer.setText(""); + AddN_info.setText(""); + } + @Override + public void mouseEntered(MouseEvent e) { + Cursor cursor = new Cursor(Cursor.HAND_CURSOR); + setCursor(cursor); + lblAddBtn.setForeground(Color.DARK_GRAY); + } + @Override + public void mouseExited(MouseEvent e) { + Cursor normalCursor = new Cursor(Cursor.DEFAULT_CURSOR); + setCursor(normalCursor); + lblAddBtn.setForeground(new Color(255, 255, 255)); + } + @Override + public void mousePressed(MouseEvent e) { + lblAddBtn.setForeground(new Color(255, 255, 255)); + } + @Override + public void mouseReleased(MouseEvent e) { + lblAddBtn.setForeground(Color.DARK_GRAY); + } + }); + lblAddBtn.setFont(new Font("¸¼Àº °íµñ", Font.BOLD, 25)); + lblAddBtn.setForeground(new Color(255, 255, 255)); + lblAddBtn.setBounds(887, 458, 50, 32); + contentPane.add(lblAddBtn); + + JPanel panel_3 = new JPanel(); + panel_3.setBackground(new Color(105, 105, 105)); + panel_3.setBounds(601, 512, 599, 10); + contentPane.add(panel_3); + + JLabel lblD_p_name = new JLabel("\uC0C1\uD488\uBA85"); + lblD_p_name.setForeground(Color.WHITE); + lblD_p_name.setFont(new Font("¸¼Àº °íµñ", Font.BOLD, 20)); + lblD_p_name.setBounds(723, 596, 60, 32); + contentPane.add(lblD_p_name); + + DP_name = new JTextField(); + DP_name.setColumns(10); + DP_name.setBounds(821, 603, 216, 21); + contentPane.add(DP_name); + + JLabel lblDeleteBtn = new JLabel("\uCD94\uAC00"); + lblDeleteBtn.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + if (new Delete_product().Delete(DP_name.getText()).equals("s")) { + // »õ·Î sus_01¿¡ Á¤º¸°¡ »èÁ¦µÇ¾ú±â¶§¹®¿¡ ÀÚµ¿È­ ÀÛ¾÷ ÇÊ¿ä + new Outo_management(); + // »óǰ »èÁ¦¿¡ ¼º°ø + JOptionPane.showMessageDialog(null, "[" + DP_name.getText() + "] »óǰÀ» ¼º°øÀûÀ¸·Î »èÁ¦Çß½À´Ï´Ù."); + } else { + // »óǰ »èÁ¦¿¡ ½ÇÆÐ + JOptionPane.showMessageDialog(null, "[" + DP_name.getText() + "] »óǰ Ãß°¡¿¡ ½ÇÆÐÇß½À´Ï´Ù."); + } + DP_name.setText(""); + } + @Override + public void mouseEntered(MouseEvent e) { + Cursor cursor = new Cursor(Cursor.HAND_CURSOR); + setCursor(cursor); + lblDeleteBtn.setForeground(Color.DARK_GRAY); + } + @Override + public void mouseExited(MouseEvent e) { + Cursor normalCursor = new Cursor(Cursor.DEFAULT_CURSOR); + setCursor(normalCursor); + lblDeleteBtn.setForeground(new Color(255, 255, 255)); + } + @Override + public void mousePressed(MouseEvent e) { + lblDeleteBtn.setForeground(new Color(255, 255, 255)); + } + @Override + public void mouseReleased(MouseEvent e) { + lblDeleteBtn.setForeground(Color.DARK_GRAY); + } + }); + lblDeleteBtn.setForeground(Color.WHITE); + lblDeleteBtn.setFont(new Font("¸¼Àº °íµñ", Font.BOLD, 25)); + lblDeleteBtn.setBounds(887, 709, 50, 32); + contentPane.add(lblDeleteBtn); } } diff --git a/project01/src/Product_management/Search_with_product_name.java b/project01/src/Product_management/Search_with_product_name.java index 7a1901e..80d018f 100644 --- a/project01/src/Product_management/Search_with_product_name.java +++ b/project01/src/Product_management/Search_with_product_name.java @@ -13,7 +13,122 @@ public class Search_with_product_name { // »óǰ¸íÀ¸·Î °Ë»öÇßÀ» ¶§ °Ë»ö °ªÀ» ¸®ÅÏÇØÁ٠Ŭ·¡½º - public String info(String product_name) { + public String product_name(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(); + + String sql = "SELECT product_name 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", rs.getString("product_name")); + } + + rs.close(); + pstmt.close(); + conn.close(); + + } catch (SQLException e) { + e.printStackTrace(); + } + return information; + + } + + public String commodity_price(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 TO_CHAR(commodity_price,'9,999,999L') as \"commodity_price\" 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", rs.getString("commodity_price")); + } + + rs.close(); + pstmt.close(); + conn.close(); + + } catch (SQLException e) { + e.printStackTrace(); + } + return information; + + } + + public String manufacturer(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(); + + String sql = "SELECT manufacturer 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", rs.getString("manufacturer")); + } + + rs.close(); + pstmt.close(); + conn.close(); + + } catch (SQLException e) { + e.printStackTrace(); + } + return information; + + } + + public String nutrition_information(String product_name) { String information = ""; Properties props = new Properties(); props.setProperty("dataSourceClassName", "oracle.jdbc.pool.OracleDataSource"); @@ -29,7 +144,7 @@ public String info(String product_name) { 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 = ?"; + String sql = "SELECT nutrition_information FROM sus_01 WHERE product_name = ?"; PreparedStatement pstmt = conn.prepareStatement(sql); @@ -38,7 +153,7 @@ public String info(String 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")); + information = String.format("[¿µ¾çÁ¤º¸]: %s", rs.getString("nutrition_information")); } rs.close();