728x90
728x90
BIG
jre 시스템 마우스오른쪽 빌드패스 콘피규 빌드패스
에드 익스터널 자르
불러오기
package helloworld;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.util.Scanner;
public class member {
static PreparedStatement pstmt ; //null
static Connection conn; // null, 인터페이스 형식
private static String id;
private static String name;
private static int height;
private static int weight;
private static int age;
public static void main(String[] args) {
// TODO Auto-generated method stub
//driver loading
String driver ="oracle.jdbc.OracleDriver";
String url = "jdbc:oracle:thin:@localhost:1521:xe";
String usid = "sample"; //id
String password = "1234"; // 비번
try {
//connection
Class.forName(driver); //로딩
System.out.println("오라클 드라이버 로딩 성공");
conn = DriverManager.getConnection(url, usid, password);
//System.out.println("오라클 연결 성공");
Scanner sc = new Scanner(System.in);
System.out.println("아이디,이름,키,몸무게,나이입력");
String id =sc.next();
String name =sc.next();
int height = sc.nextInt();
int weight = sc.nextInt();
int age = sc.nextInt();
//sql command ,걍 임포트해서 넘겨준다는 뜻
pstmt = conn.prepareStatement("insert into member values(?, ?, ?, ?, ?)");
// 물음표가 뭔지 알려주는 게 있어야됨
pstmt.setString(1, id);
pstmt.setString(2, name);
pstmt.setInt(3, height);
pstmt.setInt(4, weight);
pstmt.setInt(5, age);
pstmt.executeUpdate();
//result
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
} finally {
}
//에러잡기, finally 써주는게 좋음 근데 생략가능
}}
728x90
반응형
BIG
'🍷DataBase > 🎮Oracle' 카테고리의 다른 글
ORA-00970: missing WITH keyword 에러 잡기 (0) | 2023.02.14 |
---|---|
[Oracle]자바 오라클 sql delete, update구문, select구문 (0) | 2022.12.21 |
[Oracle]자바에 데이터베이스 연동하기 1 (0) | 2022.12.21 |
[Oracle/오라클]csv같은 외부데이터 오라클 테이블로 가져오기 (0) | 2022.11.17 |
[Oracle/오라클] 패키지 만들어서 프로시저 다루기 (0) | 2022.11.16 |
댓글