- 标签:JAVA语言、Oracle数据库、Java访问Oracle数据库
- 释义:OJDBC是Oracle公司提供的Java数据库连接驱动程序
★ 实验环境
※ Oracle 19c
※ OJDBC8
※ JDK 8
★ Java代码案例
package PAC_001;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.SQLException;
import oracle.jdbc.pool.OracleDataSource;
public class CLA_oracle {
public static void main(String args[]) throws SQLException {
OracleDataSource ods = null;
Connection conn = null;
Statement stmt = null;
ResultSet rset = null;
ods = new OracleDataSource();
ods.setURL("jdbc:oracle:thin:@1.1.1.9:1521/prodpdb1");
ods.setUser("zzt");
ods.setPassword("zzt");
conn = ods.getConnection();
try {
stmt = conn.createStatement();
rset = stmt.executeQuery("SELECT count(*) FROM zzt.emp");
while (rset.next())
System.out.println("count(*) is : " + rset.getString(1));
}
finally {
if (rset != null)
rset.close();
if (stmt != null)
stmt.close();
if (conn != null)
conn.close();
}
}
}
※ 如果您觉得文章写的还不错, 别忘了在文末给作者点个赞哦 ~