建站学院文档 1.下载oracle jdbc包,在oracle官方网站上有下载,一般是jar包或者zip包。
http://www.oracle.com/technology/software/tech/java/sqlj_jdbc/index.html
2.安装oracle jdbc包,在你的project中添加这些包,即可import oracle相应的类。
3.代码示例:
以下为引用的内容: import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.Properties; import oracle.jdbc.pool.OracleDataSource; public class Main { public static void main(String[] args) { try{ OracleDataSource ods = new OracleDataSource(); ods.setDriverType ( "thin" ); // type of driver ods.setNetworkProtocol("tcp"); // tcp is the default anyway ods.setServerName ( "127.0.0.1" ); // database server name ods.setDatabaseName("TEST"); // Oracle SID ods.setPortNumber(1521); // listener port number ods.setUser("user"); // username ods.setPassword("123456"); // password Connection conn=ods.getConnection(); PreparedStatement ps=conn.prepareStatement("select * from pipe"); ResultSet rs=ps.executeQuery(); while (rs.next()) { String source = rs.getString("SOURCE_ID"); System.out.println( source ); } System.in.read(); } catch(Exception e) { System.out.println(e.getMessage()); } |