package jdbc;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Scanner;
public class delete {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("탈퇴할 아이디 : ");
String id = sc.next();
Connection conn = null;// >전역변수빼주기
PreparedStatement psmt = null;
// 1. JDBC 동적로딩
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
// 2. DB 연결
String url = "jdbc:oracle:thin:@127.0.0.1:1521:xe";
String db_id = "hr";
String db_pw = "hr";
conn = DriverManager.getConnection(url, db_id, db_pw);
// 3. SQL문 작석 및 전송
String sql = "delete from member where id= ?";// 스트링>>'' 표시주의 ? 일때는'' 없음
psmt = conn.prepareStatement(sql);
psmt.setString(1,id);//>>(인덱스(여기서는1부터시작함),지울꺼)
int cnt = psmt.executeUpdate();
if (cnt > 0) {// >> 0보다 크게 설정 ==0 아니라
System.out.println("회원탈퇴 성공");
} else {
System.out.println("회원탈퇴 실패");
}
} catch (ClassNotFoundException e) {
System.out.println("동적 로딩 실패");
}
catch (SQLException e) {
System.out.println("DB 연결 실패");
} finally {
// 4. 통로 닫아주기
try {
if (psmt != null) {
psmt.close();
}
if (conn != null) {
conn.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}//>>밑에 }표시 확인
아직 영타가 서툴러서 영단어 치는데 자꾸 오타가 나닌깐 고치는동안 수업진도가 휘리릭 가닌깐
이해하기 너무 힘들다
없는돈 영끌해서 인체공학키보드+마우스 구매했는데
맙소사 치는게 더 낯설어진다. 영타 연습좀 많이 해야할 필요
그리고 영어 오류코드 찾기를 이해도가 많이 부족함
package jdbc;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Scanner;
public class insert {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// 사용자 화면
System.out.print("ID : ");
String id = sc.next();
System.out.print("pw : ");
String pw = sc.next();
System.out.print("name : ");
String name = sc.next();
// JDBC 연결순서(4단계)
// 선행작업 필요 : ojdbc6.jar -> 프로젝트에 라이브러로 추가
// 프로젝트 우클릭 -> build path -> cofigure build path
// 1. JDBC 동적로딩
// 동적로딩을 위한 메소드 사용
Connection conn = null;
PreparedStatement psmt = null;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
// 2. DB 연결
// DB에 접근 할 때 -> 변수를 사용해서 URL, ID, PW 를 전송
String url = "jdbc:oracle:thin:@127.0.0.1:1521:xe";// @localhost
String db_id = "hr";
String db_pw = "hr";
conn = DriverManager.getConnection(url, db_id, db_pw);
if (conn != null) {
System.out.println("연결성공");
} else {
System.out.println("연결실패");
}
// 3. SQL문 작성 및 전송
String sql = "insert into member values(?,?,?)";
psmt = conn.prepareStatement(sql);
psmt.setString(1, id);
psmt.setString(2, pw);
psmt.setString(3, name);
// CRUD : Create(생성), Read(읽기, 조회), Update(갱신, 수정), Delete(삭제)
// insert, update , delete : executeUpdate() --> int 타입
// select : executeQuery()
int cnt = psmt.executeUpdate();
if (cnt > 0) {
System.out.println("회원가입 성공!");
} else {
System.out.println("회원가입 실패!");
}
// 4. 통로 닫아주기(종료)
} catch (ClassNotFoundException e) {
System.out.println("동적 로딩 실패~");
} catch (SQLException e) {
System.out.println("DB 연결 실패~");
} finally {
// 4. 통로 닫아주기(종료)
try {
if (psmt != null) {
psmt.close();
}
if (conn != null) {
conn.close();
}
} catch (Exception e) {
}
}
}
}
package jdbc;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class select {
public static void main(String[] args) {
System.out.println("전체 조회");
Connection conn = null;
PreparedStatement psmt = null;//>>데이터 타입에 대문자
try {
String url = "jdbc:oracle:thin:@localhost:1521:xe";
String db_id = "hr";
String db_pw = "hr";//>>데이터 타입에 대문자
conn = DriverManager.getConnection(url,db_id,db_pw);
String sql = "select*from member";
psmt = conn.prepareStatement(sql);
ResultSet rs = psmt.executeQuery();
System.out.println("id\tPW\tNAME");
while (rs.next()) {//>==true 않써도 됨 데이터 타입이 broan이여서
String id = rs.getString(1);
String pw = rs.getString("pw");//2
String name = rs.getString(3);
System.out.printf("%s\t%s\t%s%n",id,pw,name);
}
Class.forName("oracle.jdbc.driver.OracleDriver");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
package jdbc;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Scanner;
public class update {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("회원 아이디 : ");
String id = sc.next();
System.out.println("비밀번호 수정 : ");
String pw = sc.next();
Connection conn = null;
PreparedStatement psmt = null;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
String url = "jdbc:oracle:thin:@localhost:1521:xe";
String db_id = "hr";
String db_pw = "hr";
conn = DriverManager.getConnection(url, db_id, db_pw);
String sql = "update member set pw = ? where id= ?";
psmt = conn.prepareStatement(sql);
psmt.setString(1, pw);
psmt.setString(2, id);
int cnt = psmt.executeUpdate();
if (cnt > 0) {
System.out.println("회원수정 성공");
} else {
System.out.println("회원수정 실패");
}
} catch (ClassNotFoundException e) {
} catch (SQLException e) {
System.out.println("DB 연결 실패");
} finally {
try {
if (psmt != null) {
psmt.close();
}
if (conn != null) {
conn.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
int[] point = {92,32,52,9,81,2,68};
int bigyo=point[0];
int a=0;
int b=0;
for(int k=0;k<point.length;k++) {
for(int i=0;i<point.length;i++) {
if(point[k]-point[i]>0) {
int cha = point[k]-point[i];
if(bigyo>cha) {
bigyo=cha;
a=k;
b=i;
}
}
}
}
System.out.printf("result = [%d, %d]",a,b);
오후에 자바페스티벌을 진행했는데 사실 나름 남들보다도 공부를 열심히 했다고 자부 했고
우리팀에 전공자가 있어서 우승할꺼라고 생각 했기에 문제를 포기하지않고 끝까지 풀기로 했는데
이걸 왠걸 현실은 꼴등을 달렸다 심지어 나는 위에사진처럼 오늘나온 문제 중 3분에 1은 틀렸다
생각보다 내가 함수 불러 오는 방법을 잘모르고 있더라 그리고 가장 큰 치욕인게 팀원에게 민폐를 끼친점이 내자신에게 화가 났다 다행이도 우리팀들이 하나같이 좋은 분들이여서 졌잘싸 라고 서로 즐겼지만은 다시한번 전체적으로 풀 필요성이 느껴졌음