我在oracle中的连接字符串“jdbc:oracle:thin:”这样怎么也可以连接上数据库??请各位帮帮忙!

解决方案 »

  1.   

    jdbc:oracle:thin:@localhost:1521:DataBaseName
      

  2.   

    jdbc:oracle:thin:@192.168.1.123:1521:orcl
      

  3.   

    java的jdbc直连。你后面没有ip:host:SID?应该连不上吧?是不是这么弄的:
    public static Connection getConn() {
    String URL = "jdbc:oracle:thin:@127.0.0.1:1521:XE";
    String user = "cartoon";// 这里替换成你自已的数据库用户名
    String password = "oracle";// 这里替换成你自已的数据库用户密码
    Connection connection = null;
    try {
    Class.forName("oracle.jdbc.driver.OracleDriver");
    System.out.println("类实例化成功!"); connection = DriverManager.getConnection(URL, user, password);
    System.out.println("创建连接对像成功!");
    } catch (Exception err) {
    err.printStackTrace();
    return null;
    } return connection;
    }
      

  4.   

    谢谢各位! 果我写成 “jdbc:oracle:thin:IP:521:SID” 就正常,如果我写成 “jdbc:oracle:thin:localhost:1521:SID" 就是怎么连接都可以。我晕呀!SID不写、1521不写,localhost不写 也行。
      

  5.   

    我的链接字符串是这样的
    private static String DRIVER="oracle.jdbc.driver.OracleDriver";
    private static String URL="jdbc:oracle:thin:localhost:1521:Orcl";
    //这些都可以链接得上
    //jdbc:oracle:thin
    //jdbc:oracle:thin:localhost:
    //jdbc:oracle:thin:localhost:1521:
    //jdbc:oracle:thin:localhost:1521:"" private static String USER="SCOTT";
    private static String PASS="tiger";
      

  6.   

    确认连进去了?可以select * from dual?
    换个用户,不要用scott/tiger试试?还有,ip前面不用@的吗?
      

  7.   

    估计是没有走监听,你这样写的话。你试着关闭监听,看是不是一样可以连接。然后再启动java程序前,把系统里的ORACLE_SID修改成别的,试试。