时间:2021-07-01 10:21:17 帮助过:2人阅读
2.连接Oracle
1)准备工作
准备Oracle驱动ojdbc14.jar,在eclipse中引用这个jar包。方法同上。
2)一段示例代码:
package connDB; import java.sql.*; import java.util.Properties; public class ConnOracle { public static void main(String [] args){ Connection conn = null; Statement statement = null; ResultSet rs = null; try{ Class.forName("oracle.jdbc.driver.OracleDriver"); String url = "jdbc:oracle:thin:@localhost:1521:orcl"; Properties props = System.getProperties(); props.put("user", "system"); props.put("password", "abcd1234"); conn = DriverManager.getConnection(url,props); statement = conn.createStatement(); rs = statement.executeQuery("SELECT * FROM TEST"); while(rs.next()){ System.out.println(rs.getString("NAME")); } }catch(Exception e){ e.printStackTrace(); }finally{ try{ if(rs!=null) rs.close(); if(statement!=null) statement.close(); if(conn!=null) conn.close(); }catch(Exception e){ e.printStackTrace(); } } } }View Code
在eclipse中Java连接Sybase和oracle的例子
标签: