zoukankan      html  css  js  c++  java
  • oracle jdbc connection string URL

    JDBC Driver Connection URL

    This section describes the connection URL format and how to create connection objects with the DriverManager class.

    If you want to use the DriverManager class to create connection objects, you need to know how to make a connection URL that provides access information to the Oracle server. The Oracle connection URL for the thin client-side driver ojdbc14.jar has the following format:

    jdbc:oracle:thin:[user/password]@[host][:port]:SID
    jdbc:oracle:thin:[user/password]@//[host][:port]/SID
    
      user - The login user name defined in the Oracle server.
    
      password - The password for the login user.
    
      host - The host name where Oracle server is running. 
             Default is 127.0.0.1 - the IP address of localhost.
    
      port - The port number where Oracle is listening for connection.
             Default is 1521.
    
      SID  - System ID of the Oracle server database instance. 
             SID is a required value. By default, Oracle Database 10g Express 
             Edition creates one database instance called XE.
    

    Here are some example connection URLs:

    jdbc:oracle:thin:Herong/TopSecret@localhost:1521:XE
    jdbc:oracle:thin:Herong/TopSecret@:1521:XE
    
    jdbc:oracle:thin:Herong/TopSecret@//localhost:1521/XE
    jdbc:oracle:thin:Herong/TopSecret@//:1521/XE
    jdbc:oracle:thin:Herong/TopSecret@//localhost/XE
    jdbc:oracle:thin:Herong/TopSecret@///XE
    

    I wrote the following program to validate some of the connection URLs listed above:

    /**
     * OracleConnectionUrl.java
     * Copyright (c) 2007 by Dr. Herong Yang. All rights reserved.
     */
    import java.sql.*;
    public class OracleConnectionUrl {
      public static void main(String [] args) {
        Connection con = null;
        try {
    
    // Load the Oracle JDBC driver
          Class.forName("oracle.jdbc.OracleDriver") ;
          System.out.println("Oracle JDBC driver loaded ok.");
    
          con = DriverManager.getConnection(
            "jdbc:oracle:thin:Herong/TopSecret@localhost:1521:XE");
          System.out.println("Connected with @localhost:1521:XE.");
          con.close();
    
          con = DriverManager.getConnection(
            "jdbc:oracle:thin:Herong/TopSecret@:1521:XE");
          System.out.println("Connected with @:1521:XE.");
          con.close();
    
          con = DriverManager.getConnection(
            "jdbc:oracle:thin:Herong/TopSecret@//localhost:1521/XE");
          System.out.println("Connected with @//localhost:1521/XE.");
          con.close();
    
          con = DriverManager.getConnection(
            "jdbc:oracle:thin:Herong/TopSecret@//:1521/XE");
          System.out.println("Connected with @//:1521/XE.");
          con.close();
    
          con = DriverManager.getConnection(
            "jdbc:oracle:thin:Herong/TopSecret@//localhost/XE");
          System.out.println("Connected with @//localhost/XE.");
          con.close();
    
          con = DriverManager.getConnection(
            "jdbc:oracle:thin:Herong/TopSecret@///XE");
          System.out.println("Connected with @///XE.");
          con.close();
    
          con = DriverManager.getConnection(
            "jdbc:oracle:thin:Herong/TopSecret@//localhost:1521");
          System.out.println("Connected with @//localhost:1521.");
          con.close();
    
        } catch (Exception e) {
          System.err.println("Exception: "+e.getMessage());
        }
      }
    }
    

    Here is the output:

    C:\>javac OracleConnectionUrl.java
    
    C:\>java -cp .;\local\lib\ojdbc14.jar OracleConnectionUrl
    
    Oracle JDBC driver loaded ok.
    Connected with @localhost:1521:XE.
    Connected with @:1521:XE.
    Connected with @//localhost:1521/XE.
    Connected with @//:1521/XE.
    Connected with @//localhost/XE.
    Connected with @///XE.
    Exception: Listener refused the connection with the following error:
    ORA-12514, TNS:listener does not currently know of service requested in connect
    descriptor
    The Connection descriptor used by the client was:
    //localhost:1521
    

    The last URL test failed, because SID was not specified. The Oracle HTTP listener could not connect the request to a database service, the SID.

  • 相关阅读:
    bzoj1015: [JSOI2008]星球大战starwar 并查集+离线处理
    bzoj1051: [HAOI2006]受欢迎的牛
    bzoj1798: [Ahoi2009]Seq 维护序列seq 线段树
    codevs1163访问艺术馆 树形dp
    国标GB28181协议视频人脸识别/车牌识别平台EasyCVR国标设备接入新增录像功能开发
    海康SDK/大华SDK安防视频智能分析平台EasyCVR接入过多通道卡顿问题解决
    网络穿透设备EasyNTS上云网关如何结合智慧工地上云平台实现视频监控的多终端观看?
    TSINGSEE青犀视频EasyCVR视频融合共享平台浏览器直播页面报错无法播放如何排查?
    【解决方案】视频智能分析平台EasyCVR是如何搭建一套完善稳定的月子会所在线视频系统的?
    RTP协议可以用于直播吗?TSINGSEE青犀视频编译RTP推流程序报错类型不匹配问题解决
  • 原文地址:https://www.cnblogs.com/wucg/p/2259635.html
Copyright © 2011-2022 走看看