1 import java.sql.Connection; 2 import java.sql.Driver; 3 import java.sql.DriverManager; 4 5 /** 6 * @author liuwenlong 7 * @create 2020-08-11 14:36:20 8 */ 9 @SuppressWarnings("all") 10 public class LwlSql { 11 public static void main(String[] args) { 12 Connection conn = null; 13 try { 14 //第一步,测试是否已经添加了操作oracle的jar包 15 Class.forName("oracle.jdbc.driver.OracleDriver"); 16 //第二步:和数据库连接 17 conn = DriverManager.getConnection("jdbc:oracle:thin:@192.168.1.3:1521:xe", "hr", "123456"); 18 19 //第三步,创建执行sql语句的对象 20 java.sql.Statement st = conn.createStatement(); 21 st.executeUpdate("create table lwl(id number(2),sex varchar(2),brith date)");//可以执行ddl+增删改 ,不能执行select 22 st.executeUpdate("insert into lwl(id,sex,brith) values(1,'a',to_date('2009-06-08','YYYY-DD-MM'))"); 23 24 System.out.println("end!"); 25 } catch (Exception e) { 26 System.err.println(e.getMessage()); 27 } 28 } 29 }