java连接Oracle数据库

import java.net.URL;
import java.sql.*;

public class JavaOracle {
  public JavaOracle() {
  }
public static void main(String[] args){
  try
  {
    try{
      Class.forName("oracle.jdbc.driver.OracleDriver");
    }
    catch(java.lang.ClassNotFoundException e)
    {
      System.err.print(e.getMessage());
    }
    String url="jdbc:oracle:thin:@Server:1521:SDCDB";
    Connection conn=DriverManager.getConnection(url,"test","test");
    Statement stmt=conn.createStatement();
    ResultSet rs=stmt.executeQuery("select score from MY");
    while(rs.next())
    {
      System.out.println(rs.getString(1));
    }
    conn.close();
  }
  catch(SQLException ex)
  {
    while(ex!=null)
    {System.out.println(ex.getSQLState());
    }
  }
}
}

 

posted @ 2012-04-18 20:41  残阳飞雪  阅读(187)  评论(0编辑  收藏  举报