// 注册驱动(oracle数据库)
Class.forName("oracle.jdbc.driver.OracleDriver");
// 获取连接
Connection conn = DriverManager.getConnection(
"jdbc:oracle:thin:@192.168.0.26:1521:test",
"root",
"1234");
// 测试连接
System.out.println(conn);
// 发送SQL
// 获取statement
Statement stat = conn.createStatement();
String sql = "select * from zzq_emp";
// 获取数据
ResultSet rs = stat.executeQuery(sql);
// 读取数据
while (rs.next()) {
// 注意:小标从1开始
// 无效的列索引(0)
System.out.println(rs.getInt(1) + " " + rs.getString(2) + " "
+ rs.getDouble(3));
}
// 释放资源关闭连接
// 关闭结果集
rs.close();
stat.close();
conn.close();