/**
* 驱动加载字符串
*/
private String className = "oracle.jdbc.driver.OracleDriver";
/**
* 数据库连接地址
*/
private String url="jdbc:oracle:thin:@localhost:1521:orcl";
/**
* 登录名
*/
private String user = "system";
/**
*
*/
private String password="orcl";
/**
* 数据库连接对象
*/
protected Connection connection;
/**
* sql语句执行命令对象
*/
protected PreparedStatement preparedStatement;
/**
* 结果集对象
*/
protected ResultSet resultSet;
/**
* 获得数库连接
* @return 数据库连接对象
*/
protected Connection openConnection(){
try {
//加载驱动
Class.forName(className);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//获得数据库连接
try {
this.connection = DriverManager.getConnection(url, user, password);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return this.connection;
}
protected void closeConnection(){
if(this.resultSet!=null){
try {
//关闭结果集
this.resultSet.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(this.preparedStatement!=null){
//关闭sql执行对象
try {
this.preparedStatement.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(this.connection!=null){
//关闭连接
try {
this.connection.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Java中使用JDBC连接oracle数据库
原创
©著作权归作者所有:来自51CTO博客作者口袋里的小龙的原创作品,请联系作者获取转载授权,否则将追究法律责任
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
Oracle JDBC 连接
Oracle JDBC 连接
Oracle JDBC 连接 -
jdbc:连接oracle
jdbc是经典的数据库链接方式 导入jar包,即链接包即可。在框架中,框架可以轻
jdbc java sql List -
JAVA JDBC连接oracle 测试代码
JAVA JDBC连接oracle 测试代码
JAVA oracle JDBC -
Java-Jdbc,JDBC连接Oracle11g实例:
很长时间没用Oracle数据了,今天在公司d
java oracle11g jdbc oracle sql -
javacv 提高人脸准确的
技术栈:Spring boot 2.x腾讯java版本1.8注意事项:本文内的“**.**”需要自己替换为自己的路径。常量内的“**”需要自己定义自己内容。业务中认证图片,上传至阿里云OSS上话不多说,直接上代码1、pom文件:<!-- apache httpclient组件 --> <dependency> <groupId>org.apache.h
javacv 提高人脸准确的 java java AI 对接 java腾讯AI对接 java人脸对比