JAVA 连接ORACLE10g 代码

import java.sql.*;

public class JDBCExample {
 
 public static void main(String[] args) throws SQLException{
  try {
      Class.forName("oracle.jdbc.driver.OracleDriver");
  } catch (ClassNotFoundException e) {
      e.printStackTrace();
  }
  Connection conn=DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:orcl","system","orcl");

// conn=DriverManager.getConnection("jdbc:oracle:thin:@ip地址:1521:数据库名", "用户名", "密码");
  Statement stmt=conn.createStatement();
  ResultSet rset=stmt.executeQuery("select * from t_pm_user");
  while(rset.next())
      System.out.println(rset.getString(1));
  stmt.close();
  }
}

 

注:ORACLE 10g 默认安装目录下已有jdbc oracle驱动JAR。

D:\oracle\product\10.2.0\db_1\jdbc\lib\ojdbc14.jar。

 

你可能感兴趣的:(JAVA 连接ORACLE10g 代码)