时间:2021-07-01 10:21:17 帮助过:4人阅读
public class TestUpdate { public static void main(String[] args) throws ClassNotFoundException, SQLException { //1加载驱动 Class.forName("oracle.jdbc.driver.OracleDriver"); //2创建连接对象 Connection conn=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl", "scott","oracle"); //3创建sql命令对象 Statement stmt=conn.createStatement(); //4创建sql命令 String sname="张三"; String sql="update student set sname=‘"+sname+"‘ where snum=2"; //5执行sql命令 int i=stmt.executeUpdate(sql); System.out.println(i); //6关闭资源 stmt.close(); conn.close(); } }
public class TestDel { public static void main(String[] args) throws ClassNotFoundException, SQLException { //1 加载驱动 Class.forName("oracle.jdbc.driver.OracleDriver"); //2创建连接对象 Connection conn=DriverManager.getConnection("jdbc:oracle:thin:@LocalHost:1521:orcl", "scott", "oracle"); //3创建sql命令对象 Statement stmt=conn.createStatement(); //4创建sql命令 String sql="delete from student where snum=2"; //5执行sql命令 int i=stmt.executeUpdate(sql); System.out.println("删除数据量:"+i); //6关闭资源 stmt.close(); conn.close(); } }
JDBC1
标签:scott nts 获取 rate oid jdb connect for java