package com.test.jdbc; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; public class Test4 { public static void main(String[] args) { try { findPc(); } catch (Exception e) { // TODO 自动生成的 catch 块 e.printStackTrace(); } } public static void findPc() throws Exception{ //加载驱动 Class.forName("oracle.jdbc.driver.OracleDriver"); //获取连接 String url = "jdbc:oracle:thin:@localhost:1521:XE"; String user = "orac"; String password = "123456"; Connection conn = DriverManager.getConnection(url, user, password); //获取执行对象 String sqlStr = "delete from pc where pname=‘k665‘"; PreparedStatement pst = conn.prepareStatement(sqlStr); //调用方法处理,获取结果 int num = pst.executeUpdate(); //处理结果 if(num>0) System.out.println("删除成功"); else System.out.println("删除失败"); //关闭 pst.close(); conn.close(); } }
时间: 2024-10-09 15:27:15