피드로 돌아가기
새로워지기·서른의 생활코딩

ex) java_ JDBC

NS
normalstory
표지 이미지

import java.awt.*;        // 멀티미디어, 
import java.awt.event.*;  // 윈도우관련 이벤트
import java.net.*;        // 네트워크관련 패키지
import java.sql.*; 


class JDBCTest extends Frame {   // 윈도우 구조
static TextArea myTextArea;  // TextArea = 엔터키 쳐 가면서 여러 라인 입력할 수 있도록 해줌
//1
public JDBCTest() {//생성자
super("Simple JDBC Application");
addWindowListener(new WindowAdapter() {  // 윈도우관련 이벤트(종료)
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
setLayout(new FlowLayout()); //원래 윈도우 boderLayout ->FlowLyout으로 배치 변경
myTextArea = new TextArea(25, 50);
                                      //myTextArea객체정의 (라인수,문자수)만큼의 myTextArea 생성
 
add(myTextArea); //앞에 this 생략 (componant의 Frame사용!!) : 프레임 
setSize(500, 500); //앞에 this 생략 (componant의 Frame사용!!) : 전체 윈도우
setVisible(true);  //화면에 윈도우를 보여줌!
myTextArea.append("Please wait while the SQL query executes...\n"  //안에 프레임
);
}//여기까지 생성자의 역할 !!!!
//3:출력
static void displayResults(ResultSet results) throws SQLException{
        // 스태틱, 객체정의안하고도  + .으로 연결가능
ResultSetMetaData resultsMetaData = results.getMetaData ();
                 //셀랙트된 구조를 저장해 줄  ResultSetMetaData의 객체정의(필드명,타입,갯수..)
int cols = resultsMetaData.getColumnCount();  //cols = 필드의 갯수=4
 
while (results.next()) {   //results마지막 레코드 + next()커서 이동
for (int i=1; i<=cols; i++) { //트루일 경우 ,cols = 필드의 갯수=4
if (i > 1) myTextArea.append("\t");  // "\t"=행간 간격 띄워가며 출력
myTextArea.append(results.getString(i));  //i= i번째 필드
}
myTextArea.append("\n");
}
}
//2
public static void main(String argv[]) throws SQLException, Exception {
String theQuery = "SELECT id,irum,juso,tel FROM addr"; // SELECT 문장 
                          // *(모두인 경우) = id,irum,juso,tel=필드명
                                          // SQL문의 예약어 = FROM (+ 테이블명)(+where 조건식)
JDBCTest myJDBCTest = new JDBCTest();
                // 전체 클래스타입의 객체 정의 ->JDBCTest -> 생성자 자동 호출(초기화를 위해)
//Object-> compernant-> container(다른컨트롤사용)
                   -> window(다이얼로그와 공동사용시 속성참조용)-> Frame(super)-> JDBCTest(this)

 //(프로세스:)->super("Simple JDBC Application"); 윈도우 창이름 생성 -> 생성자 실행

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); // 드라이브명 기재! 
Connection myCon =
DriverManager.getConnection("jdbc:odbc:Addr", "aaa", "bbb");  
                // getConnection 스태틱 변수 -> .으로 접근
        // 제어판 ODBC에서의 이름 jdbc:odbc:Addr + 암호

 
// Test는 ODBC드라이브명
// aaa는 사용자명
// bbb는 패스워드
Statement MyStmt = myCon.createStatement();  
                //createStatement  ->Statement의 포인터를 반환
ResultSet myResults = MyStmt.executeQuery(theQuery);  
                //ResultSet=저장  / theQuery="sun.jdbc.odbc.JdbcOdbcDriver"
displayResults(myResults);
                //displayResults스태틱맴버함수를 매개변수로해서 ->displayResults  
//결과를 보여줄 myResults 객체생성
myResults.close();
MyStmt.close();
myCon.close();
}
}


// 스터디  : SQL문장 배우기   -> 스트럿츠  -> 스프링   -> jQuery -> 안드로이드  
  • Open in Google Docs Viewer
  • Open link in new tab
  • Open link in new window
  • Open link in new incognito window
  • Download file
  • Copy link address
  • Edit PDF File on PDFescape.com

element

Font
font-family
font-size
font-style
font-variant
font-weight
letter-spacing
line-height
text-decoration
text-align
text-indent
text-transform
white-space
word-spacing
color
Background
bg-attachment
bg-color
bg-image
bg-position
bg-repeat
Box
width
height
border-top
border-right
border-bottom
border-left
margin
padding
max-height
min-height
max-width
min-width
outline-color
outline-style
outline-width
Positioning
position
top
bottom
right
left
float
display
clear
z-index
List
list-style-image
list-style-type
list-style-position
Table
vertical-align
border-collapse
border-spacing
caption-side
empty-cells
table-layout
Effects
text-shadow
-webkit-box-shadow
border-radius
Other
overflow
cursor
visibility
친절한 찰쓰씨
글쓴이
친절한 찰쓰씨
친절한 찰쓰씨 · 일상 UX 디자이너
기획·디자인·단상을 조용히 기록합니다.
작가 페이지에서 더 보기

이어서 읽기

새로워지기

꾸준히, 오래, 지치지 않고

Mar 31, 2026·8
새로워지기

테크 라이프 발란스

Feb 7, 2026·3
새로워지기

휴탈리티 박정렬

Feb 7, 2026·11