Myeclipse连接数据库删除数据库(JDBC)
时间:2021-07-01 10:21:17
帮助过:4人阅读
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();
}
}
Myeclipse连接数据库删除数据库(JDBC)
标签:acl pass void res prepare static sys jdb close