https://pan.baidu.com/s/1ZCFLUi4Ti_WUYOFR3gB2dA 是11g版本下载包,下载下来解压就能用了。
安装完毕后,驱动包在【oralcehome】product11.2.0dbhome_1jdbclib下。
访问Oracle的JDBC程序,建表请见 https://www.cnblogs.com/xiandedanteng/p/11691113.html
package com.hy; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.text.MessageFormat; public class OracleConnector { // 连接到数据库的四大属性 private static final String DRIVER = "oracle.jdbc.driver.OracleDriver"; private static final String DBURL = "jdbc:oracle:thin:@127.0.0.1:1521:orcl"; private static final String USER = "system"; private static final String PSWD = "Ufo12345678"; public static void testConnToDB() { Connection conn = null; Statement stmt = null; try{ Class.forName(DRIVER).newInstance(); conn = DriverManager.getConnection(DBURL, USER, PSWD); stmt = conn.createStatement(); String sql = "select id,name,age,createdtime from firsttb"; ResultSet rs = stmt.executeQuery(sql); int index = 0; while (rs.next()) { index++; String id = rs.getString("id"); String name = rs.getString("name"); String age = rs.getString("age"); String cdate = rs.getString("createdtime"); String raw = "#{0},{1},{2},{3},{4}"; Object[] arr = { index, id, name, age, cdate }; String outStr = MessageFormat.format(raw, arr); System.out.println(outStr); } } catch (Exception e) { System.out.print(e.getMessage()); } finally { try { stmt.close(); conn.close(); } catch (SQLException e) { System.out.print("Can't close stmt/conn because of " + e.getMessage()); } } } /** * 执行点 * @param args */ public static void main(String[] args) { testConnToDB(); } }
输出:
#1,1,ANDY,20,2019-11-09 09:19:10 #2,2,Bill,30,2019-11-09 09:19:39 #3,3,Cindy,40,2019-11-09 09:19:45