728x90
데이터 입력문 을
INSERT INTO notice (
title,
writer_id,
content,
files
) VALUES (
:v0,
:v1,
:v2,
:v3
);
JAVA ECLIPSE로 작성하기
main문 안에 넣으면 된다.
String title = "test2";
String writer_id = "newlec";
String content = "hahaha";
String files = "";
String url = "jdbc:oracle:thin:@localhost:1521/xepdb1";
String sql = "INSERT INTO notice ("
+ " title,"
+ " writer_id,"
+ " content,"
+ " files"
+ ") VALUES (?,?,?,?)";
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con = DriverManager.getConnection(url,"newlec","1115");
PreparedStatement st = con.prepareStatement(sql);
st.setString(1, title);
st.setString(2, writer_id);
st.setString(3, content);
st.setString(4, files);
int result = st.executeUpdate();
System.out.println(result);
st.close();
con.close();
value값을 values(?,?,?,?)로 작성하면 prepareStatement로 set 할수 있다.
728x90