-
Threadclassnew Thread(Runnable r)start(): 인자로 들어온Runnable객체의run()메서드 실행sleep(int n):nms 휴식interrupted(): 중지
-
Data Stream
InputStreamclass<InputStreamObject>.read(): 스트림에서 읽어들임
OutputStreamclass<OutputStreamObject>.write(int o): 출력할 스트림에 쓰기
-
Character Stream
FileReaderclass- 파일에서 문자열 읽어와 스트림에 입력
FileWriterclass- 스트림에서 문자열 읽어와 파일에 입력
-
혼합 Stream
InputStreamReaderclass- web -> byte ->
InputStreamReader-> String
- web -> byte ->
OutputStreamReaderclass- String ->
OutputStreamReader-> byte
- String ->
-
Buffer Stream
BufferedReaderclassBufferedReader in = new BufferedReader(new InputStreamReader(System.in))
-
Network
java.net.URLclass- constructor
new URL(String s)new URL(URL baseURL, String relativeURL)new URL(String protocol, String host, String fileName)new URL(String protocol, String host, int port, String fileName)
openStream()BufferedReader in = new BufferedReader(new InputStreamReader(<URLObject>.openStream()))
- constructor
-
Application
Socketclassnew Socket(String host, int port)constructor
ServerSocketclasspublic ServerSocket(int port)constructorSocket accept(): 접속 요청 받고, 해당 접속에 대한 소켓 반환
-
DB SQL
- Data define instructions
CREATE: 컬럼명과 데이터 타입으로 테이블 생성ALTER: 테이블의 컬럼 추가/삭제DROP: 테이블 삭제USE: 사용할 DB 명시
- Data manufacturing instructions
SELECT: DB로부터 데이터 쿼리 및 출력INSERT: 새로운 레코드 테이블에 추가DELETE: 지정된 레코드 삭제UPDATE: 레코드 값 변경
- Data define instructions
-
JDBC (
java.sql.*)Class.forName('com.mysql.jdbc.Driver'); // with ClassNotFoundException ex.- load JDBC class driver
ClassNotFoundException: failed to find jdbc driver
Connection DriverManager.getConnection(String url, String user, String pw); // SQLExceptionString url := "jdbc:mysql//localhost/use_db"SQLException: failed to connect
Statement <ConnectionObject>.createStatement();- get statement object
ResultSet <StatementObject>.executeQuery(String query);- execute the SQL query and get a
ReaultSetobject
- execute the SQL query and get a
-
ReslutSetclassclose()last(): cursor to last recordgetRow(): get an index number of rownext(): next recordprevious(): previous recordabsolute(int rownum): move to rownum recordisFirst()isLast()get<Type>(int columnIndex), get<Type>(String columnName)
-
stmt update
stmt.executeUpdate(String sql);
-
updatable
ResultSetobject- 이를 위해서는 맨 처음
Statement객체 생성할 때, 옵션을 줘야만 한다.Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);ResultSet rs = stmt.executeQuery("SELECT * FROM users");
cancelRowUpdate()insertRow(): 현재 레코드에 대해 insertdeleteRow(): 현재 레코드에 대해 deleteupdateRow(): 현재 레코드에 대해 updateupdate<Type>(String columnName, <Type> value): 값 업데이트
- 이를 위해서는 맨 처음
import java.net.*;
public class Main {
public static void main(String[] args) {
try {
URL url = new URL("http://java.sun.com/");
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
while ((String line = in.readeLine()) != null) {
System.out.prnitln(line);
}
in.close();
} catch (IOException) {
// input out exception
}
}
}// 1: import module
import java.sql.*;
public class Main {
public static void main(String[] args) {
Connection con;
try {
// 2: dynamic-import module
Class.forName("com.mysql.jdbc.Driver");
// 3: get connectino
con = DriverManager.getConnection("jdbc:mysql://localhost/user_db", "username", "password");
} catch (ClassNotFoundException ex) {
// failed to find the mysql-jdbc driver
} catch (SQLException ex) {
// failed to connect
}
// 4: create statement
Statement stmt = con.createStatement();
Statement stmt_updatable = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
// 5: executy query
ResultSet rs = stmt.executeQuery("SELECT * FROM users");
ResultSet rs_updatable = stmt.executeQuery("SELECT * FROM users");
// executy query (update)
stmt.executeUpdate("INSERT INTO users (username, age) VALUES ('Darwin', '10')");
// 6: interate result set
while (rs.next()) {
int id = rs.getInt("userid");
String name = rs.getString("username");
}
while (rs_updatable.next()) {
rs_updatable.updateString("username", "UPDATED_" + rs_updatable.getString("username"));
rs_updatable.updateRow();
}
}
}