import java.awt.*;
import java.sql.*;

import javax.swing.*;

public class Swing02 extends JFrame
{
        
        Swing02()
        {
               
                try
               {
                        UIManager. setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel");
               }
                catch (Exception e )
               {
                        e.printStackTrace();
               }
               
               setTitle( "입력창");
                setDefaultCloseOperation( JFrame. EXIT_ON_CLOSE);
               
               setLayout( new FlowLayout( FlowLayout. LEFT)); // 레이아웃 설정
               
               add( new JLabel( "이름 : "));
               add( new JTextField(10));
               add( new JLabel( "학과 : "));
               add( new JTextField(10));
               add( new JLabel( "학번 : "));
               add( new JTextField(10));
               
               setSize(350, 200);
               setVisible( true);
        }
        
         public static void main(String [] args)
        {
                new Swing02(); // 생성자 호출
               
                try
               {
                        Class. forName("com.mysql.jdbc.Driver"); // jdbc 드라이버 로드
                       Connection conn = DriverManager.getConnection( "jdbc:mysql://localhost:3306/sampledb" , "root" , "1234" ); // 연결
                        System. out.println("JDBC Connection Complete!");
                       
                       Statement stmt = conn.createStatement();
                       
                        // insert문 실행
                        // stmt.executeUpdate("insert into student values('천준영', '정보통신학', '2014074003')");
                       
                        // update문 실행
                        // stmt.executeUpdate("update student set id='2014000001' where name='최규식'");
                       
                        // delete문 실행
                        // stmt.executeUpdate("delete from student where id='2014000001'");
                       
                        // select문 실행
                       ResultSet rs = stmt.executeQuery( "select * from student"); // SQL문이 rs에 저장된다.         
                        while(rs .next())
                       {
                               System. out.print(rs .getString("name") + "\t"); // 이름 출력
                               System. out.print(rs .getString("dept") + "\t"); // 학과 출력
                               System. out.print(rs .getString("id") + "\n"); // 학번 출력
                       }
                        rs.close(); // ResultSet을 닫는다.
                        conn.close(); // Connection을 닫는다. (메모리 자원낭비 방지)
               }
                catch(Exception e )
               {      
                        System. out.println(e .getStackTrace());
               }
        }
}