import java.sql.Connection;
import java.sql.*;
public class JdbcEx1 {
public static void main(String[] args){
Connection conn = null;
Statement stmt = null;
try {
String strUrl = "jdbc:oracle:thin:@211.183.2.35:1521:orcl";
String strId = "scott";
String strPwd = "tiger";
Class.forName("oracle.jdbc.driver.OracleDriver");
System.out.println("드라이버 로드 성공");
conn = DriverManager.getConnection(strUrl, strId, strPwd);
System.out.println("데이터베이스 연결 성공");
stmt = conn.createStatement();
//String query = "insert into dept2 values (1, '영업부', '서울')";
String query ="create table dept21 as select * from dept where 1 != 1";
stmt.executeUpdate(query);
System.out.println("데이터 입력성공");
} catch (ClassNotFoundException e) {
System.out.println("드라이버 로드 실패");
} catch (SQLException e){
System.out.println("데이터베이스 연결 실패" +e.toString());
} finally{
if(conn != null) try{ conn.close(); } catch(SQLException e) {}
}
}
}
import java.sql.Connection;
import java.sql.*;
public class JdbcEx2 {
public static void main(String[] args){
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try {
String strUrl = "jdbc:oracle:thin:@211.183.2.35:1521:orcl";
String strId = "scott";
String strPwd = "tiger";
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection(strUrl, strId, strPwd);
stmt = conn.createStatement();
String query = "select * from dept";
rs = stmt.executeQuery(query);
} catch (ClassNotFoundException e) {
System.out.println("드라이버 로드 실패");
} catch (SQLException e){
System.out.println("데이터베이스 연결 실패" +e.toString());
} finally{
if(rs != null) try{ conn.close(); } catch(SQLException e) {}
if(stmt != null) try{ conn.close(); } catch(SQLException e) {}
if(conn != null) try{ conn.close(); } catch(SQLException e) {}
}
}
}
import java.sql.Connection;
import java.sql.*;
public class JdbcEx2 {
public static void main(String[] args){
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try {
String strUrl = "jdbc:oracle:thin:@211.183.2.35:1521:orcl";
String strId = "scott";
String strPwd = "tiger";
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection(strUrl, strId, strPwd);
stmt = conn.createStatement();
String query = "select * from emp";
rs = stmt.executeQuery(query);
while(rs.next()){
System.out.print(rs.getInt("empno") + " : ");
System.out.print(rs.getString("ename") + " : ");
System.out.print(rs.getString("job") + " : ");
System.out.print(rs.getInt("mgr") + " : ");
System.out.print(rs.getInt("sal") + " : ");
System.out.print(rs.getInt("comm") + " : ");
System.out.print(rs.getInt("deptno") + "\n");
}
} catch (ClassNotFoundException e) {
System.out.println("드라이버 로드 실패");
} catch (SQLException e){
System.out.println("데이터베이스 연결 실패" +e.toString());
} finally{
if(rs != null) try{ rs.close(); } catch(SQLException e) {}
if(stmt != null) try{ stmt.close(); } catch(SQLException e) {}
if(conn != null) try{ conn.close(); } catch(SQLException e) {}
}
}
}
import java.sql.*;
public class JdbcEx1 {
public static void main(String[] args){
Connection conn = null;
Statement stmt = null;
try {
String strUrl = "jdbc:oracle:thin:@211.183.2.35:1521:orcl";
String strId = "scott";
String strPwd = "tiger";
Class.forName("oracle.jdbc.driver.OracleDriver");
System.out.println("드라이버 로드 성공");
conn = DriverManager.getConnection(strUrl, strId, strPwd);
System.out.println("데이터베이스 연결 성공");
stmt = conn.createStatement();
//String query = "insert into dept2 values (1, '영업부', '서울')";
String query ="create table dept21 as select * from dept where 1 != 1";
stmt.executeUpdate(query);
System.out.println("데이터 입력성공");
} catch (ClassNotFoundException e) {
System.out.println("드라이버 로드 실패");
} catch (SQLException e){
System.out.println("데이터베이스 연결 실패" +e.toString());
} finally{
if(conn != null) try{ conn.close(); } catch(SQLException e) {}
}
}
}
import java.sql.*;
public class JdbcEx2 {
public static void main(String[] args){
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try {
String strUrl = "jdbc:oracle:thin:@211.183.2.35:1521:orcl";
String strId = "scott";
String strPwd = "tiger";
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection(strUrl, strId, strPwd);
stmt = conn.createStatement();
String query = "select * from dept";
rs = stmt.executeQuery(query);
} catch (ClassNotFoundException e) {
System.out.println("드라이버 로드 실패");
} catch (SQLException e){
System.out.println("데이터베이스 연결 실패" +e.toString());
} finally{
if(rs != null) try{ conn.close(); } catch(SQLException e) {}
if(stmt != null) try{ conn.close(); } catch(SQLException e) {}
if(conn != null) try{ conn.close(); } catch(SQLException e) {}
}
}
}
import java.sql.*;
public class JdbcEx2 {
public static void main(String[] args){
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try {
String strUrl = "jdbc:oracle:thin:@211.183.2.35:1521:orcl";
String strId = "scott";
String strPwd = "tiger";
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection(strUrl, strId, strPwd);
stmt = conn.createStatement();
String query = "select * from emp";
rs = stmt.executeQuery(query);
while(rs.next()){
System.out.print(rs.getInt("empno") + " : ");
System.out.print(rs.getString("ename") + " : ");
System.out.print(rs.getString("job") + " : ");
System.out.print(rs.getInt("mgr") + " : ");
System.out.print(rs.getInt("sal") + " : ");
System.out.print(rs.getInt("comm") + " : ");
System.out.print(rs.getInt("deptno") + "\n");
}
} catch (ClassNotFoundException e) {
System.out.println("드라이버 로드 실패");
} catch (SQLException e){
System.out.println("데이터베이스 연결 실패" +e.toString());
} finally{
if(rs != null) try{ rs.close(); } catch(SQLException e) {}
if(stmt != null) try{ stmt.close(); } catch(SQLException e) {}
if(conn != null) try{ conn.close(); } catch(SQLException e) {}
}
}
}
'Study > Programming' 카테고리의 다른 글
자바 데이터 변경 (0) | 2009.05.25 |
---|---|
자바 우편번호 찾기 (0) | 2009.05.25 |
자바 Swing 달력 (0) | 2009.05.22 |
자바 File IO 받은 문자 출력, 파일 생성/삭제/변경 (0) | 2009.05.22 |
자바 IO 문자기반 (0) | 2009.05.22 |