Document1. Download the oracle jdbc package, which is usually a jar package or zip package on the official oracle website.
Http://www.oracle.com/technology/software/tech/java/sqlj_jdbc/index.html
2. Install the oracle jdbc package and add these packages to your project to import the corresponding oracle class.
3. Sample Code:
Reference content is as follows: 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 rsw.ps.exe cuteQuery (); While (rs. next ()) { String source = rs. getString ("SOURCE_ID "); System. out. println (source ); } System. in. read (); } Catch (Exception e) { System. out. println (e. getMessage ()); } |