eclipse连接oracle数据库

第一步:配置好oracle的环境变量

第二步把jar包导入到reference libraries

点击工程名build path->add external......

第三部具体代码

public class hello {
 @SuppressWarnings("unused")
 public static void main(String[] args) {
        System.out.println("Hello World!");

       
        String user="SYSTEM";
        String passwd="Zhuying123";
        String url="jdbc:oracle:thin:@localhost:1521:orcl";
        try
        {
            Class.forName("oracle.jdbc.driver.OracleDriver");
           Connection connection=DriverManager.getConnection(url, user, passwd);
            System.out.println("success");
        }catch (SQLException e) {
            // TODO: handle exception
            e.printStackTrace();
        }
        catch (ClassNotFoundException e) {
            // TODO: handle exception
            e.printStackTrace();
        }
 }
}


你可能感兴趣的:(Java开发)