第 32 节 PreparedStatment接口
Statement接口问题
public class TestDemo {
private static final String DBDRIVER = "oracle.jdbc.driver.OracleDriver";
private static final String DBURL = "jdbc:oracle:thin:@localhost:1521:orcl";
private static final String USER = "scott";
private static final String PASSWORD = "tiger";
public static void main(String[] args) throws Exception {
String name = "Mr'SMITH";
String birthday = "1998-10-10";
int age = 18;
String note = "是个歪果仁";
// 1.加载数据库驱动程序,此时不需要实例化,因为会由容器自己负责管理
Class.forName(DBDRIVER);
// 2.连接数据库
Connection conn = DriverManager.getConnection(DBURL, USER, PASSWORD);
// 3.进行数据库的数据操作
Statement stmt = conn.createStatement();
// 在编写SQL的过程里面,如果太长的时候需要增加换行,一定要加上前后空格
String sql = "INSERT INTO member(mid, name, birthday, age, note) VALUES " + " (myseq.nextval, '" + name
+ "', TO_DATE('" + birthday + "','yyyy-mm-dd'), " + age + ", '" + note + "')";
System.out.println(sql);
int len = stmt.executeUpdate(sql); // 执行SQL返回更新的数据行
System.out.println("影响的数据行:" + len);
// 4.关闭数据库
conn.close();
}
}PreparedStatment操作
最后更新于