Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
80 changes: 80 additions & 0 deletions project01/src/Product_management/Create_tables.java
Original file line number Diff line number Diff line change
@@ -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)");
}

}
}
191 changes: 191 additions & 0 deletions project01/src/Product_management/Main_frame.java
Original file line number Diff line number Diff line change
@@ -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));
}
}
57 changes: 57 additions & 0 deletions project01/src/Product_management/Outo_management.java
Original file line number Diff line number Diff line change
@@ -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();
}
}

}
55 changes: 55 additions & 0 deletions project01/src/Product_management/Search_with_product_name.java
Original file line number Diff line number Diff line change
@@ -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;

}

}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.