使用java datasource 進行 oracle jdbc 連接
來源:程序員人生 發布時間:2014-05-23 20:55:37 閱讀次數:4114次
建站學院文檔 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()); } |
生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈