Java语言 链接Oracle数据库

 1 package com.tao.pojo;
 2 
 3 import java.sql.Connection;
 4 import java.sql.DriverManager;
 5 import java.sql.PreparedStatement;
 6 import java.sql.ResultSet;
 7 import java.sql.SQLException;
 8 
 9 public class TestOracle001 {
10     public static void main(String[] args) throws ClassNotFoundException, SQLException {
11         Class.forName("oracle.jdbc.OracleDriver");
12 //        10.96.113.212 是数据库所在的主机的IP地址 users也是该主机的表名(连谁的数据库就用谁数据库里面的表)
13         Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@//10.96.113.212:1521/orcl", "scott", "tiger");
14         PreparedStatement ps = conn.prepareStatement("select * from users");
15         ResultSet rs = ps.executeQuery();
16         while(rs.next()) {
17             int id= rs.getInt(1);
18             String name = rs.getString(2);
19             System.out.println(id+","+name);
20         }
21         rs.close();
22         ps.close();
23         conn.close();
24     }
25 
26 }

 

posted @ 2018-01-05 15:49  理想的诱惑  阅读(234)  评论(0编辑  收藏  举报