oracle_jdbc_insert_into

 package com.ayang.jdbc;

 import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement; public class TestDML { public static void main(String[] args) {
Connection conn = null;
Statement stmt = null; try{
//1、注册驱动
//new oracle.jdbc.driver.OracleDriver();
Class.forName("oracle.jdbc.driver.OracleDriver");
//2、建立连接
conn = DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:ORCL","scott", "root");
//3、创建语句
stmt = conn.createStatement();
String sql = "insert into dept2 values(80,'GAME','BJ')";
stmt.executeUpdate(sql);
}catch (ClassNotFoundException e) {
System.out.println("未正常加载jdbc驱动");
e.printStackTrace();
}catch(SQLException e){
e.printStackTrace(); //log for java }finally{
//6、释放资源
try {
if(stmt != null){
stmt.close();
stmt = null;
}if(conn != null){
conn.close();
conn = null;
}
} catch (SQLException e) {
e.printStackTrace();
} }
} }

oracle-jdbc 执行DML语句,不需要 第四步:执行语句 5:处理结果了。表是oracle的dept表。

上一篇:iframe自适应高度处理方案


下一篇:Spring Cloud微服务笔记(三)服务治理:Spring Cloud Eureka快速入门