티스토리 뷰
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class JdbcInsertTest {
public static void main(String[] args) {
Connection conn = null;
PreparedStatement pstmt = null;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl", "scott", "tiger");
String query = "insert into dept2 values(?, ?, ?)";
pstmt = conn.prepareStatement(query);
//pstmt.set~은 conn.prepareStatement(); 다음에 들어와야한다
pstmt.setInt(1, 50);
pstmt.setString(2, "총무부");
pstmt.setString(3, "서울");
int count = pstmt.executeUpdate();
System.out.println("영향받은 행수 : " + count);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
} finally{
if(pstmt != null) try{ pstmt.close();} catch(SQLException e){};
if(conn != null) try{ conn.close();} catch(SQLException e){};
}
}
}
출처: http://whdvy777.tistory.com/entry/JDBC-preparedStatementinsert-%EC%8B%A4%EC%8A%B5
'자바(Java) > JDBC' 카테고리의 다른 글
No suitable driver found for jdbc:mariadb://11:3306?allowMultiQueries=true (0) | 2023.09.13 |
---|---|
ORA-00928: missing SELECT keyword (0) | 2017.09.07 |
oracle 에서 jdbc로 년월일 시분초 읽어오기 - java.sql.SQDataException: ORA-01861: 리터럴이 형식 문자열과 일치하지 않음 (0) | 2017.08.07 |
jdbc select - java jdbc 프로그래밍 - 자바강좌 (0) | 2017.08.01 |
JDBC, 오라클 DB 연결하기 - jdbc oracle connection (0) | 2017.07.28 |
- Total
- Today
- Yesterday
- 문자열
- 이클립스
- MySQL
- Python
- 플러터
- 자바
- 인포믹스
- 오라클
- php
- 파싱
- 포인터
- esql
- proc
- XE3
- ocajp
- C
- 파이썬
- xe애드온
- xe addon
- ocjap
- KG
- XE
- 자바 smtp
- 라이믹스 모듈
- webix
- 프로씨
- C언어
- EC
- JDBC
- 스크래핑
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |