zoukankan      html  css  js  c++  java
  • java.sql.SQLException:指定了无效的 Oracle URL

    java.sql.SQLException:指定了无效的 Oracle URL

    昨天晚上用MyEclipse连接Oracle,出现了“ java.sql.SQLException: 指定了无效的 Oracle URL”的错误,但是太晚了,就休息了。刚才在Google上搜索了一下,感觉自己的代码是没有问题的。
    url="jdbc:oracle:thin@localhost:1521:orcl";
    即格式为:jdbc:oracle:thin@IP地址:1521:数据库SID。
    后来发现,我忽略了一个细节:就是在"thin"的后面也是有个冒号的!!!正确的应该是
    url="jdbc:oracle:thin:@localhost:1521:orcl"; 
    细节啊……很重要。
    至于驱动的安装和我上一篇内容一致,只不过注册的是Oracle安装包下的jdbc文件夹里面的class12.jar。
    附基本操作代码:

    import java.sql.*;

    public class OracleConnectionDemo {
        private static final String DBDRIVER="oracle.jdbc.driver.OracleDriver";
        private static final String DBURL="jdbc:oracle:thin:@127.0.0.1:1521:MyOracle";
        private static final String DBUSER="scott";
        private static final String DBPWD="xiaoxiao";
        
        public OracleConnectionDemo()throws Exception{
                  Class.forName(DBDRIVER);
                  Connection conn=DriverManager.getConnection(DBURL,DBUSER,DBPWD);
                  String sql="select empno,ename,sal from emp";
                  PreparedStatement ps=conn.prepareStatement(sql);
                  
                 //获得EMP表中的信息。
                  ResultSet rs=ps.executeQuery();
                  while(rs.next()){
                      String empno=rs.getString(1);
                      String empname=rs.getString(2);
                      int sal=rs.getInt(3);
                      System.out.println("empno :"+empno+"  empname:"+empname+"  sal:"+sal);
                  }
                  rs.close();
                  ps.close();
                  conn.close();
                  System.out.println(" Operate Over!");
        }
        
        public static void main(String args[])throws Exception{
              new OracleConnectionDemo();
        }

    }


  • 相关阅读:
    安装armadillo
    windows sublime 2 破解
    ubuntu10.04安装有线网卡驱动
    x250装无线网卡驱动ubuntu
    main restricted universe muitiverse
    apt-get error
    新系統必須安裝的軟件列表
    更新ubuntu軟件源爲阿里雲腳本
    轉載:让重定向>,>>具有root权限
    margin的相关属性:
  • 原文地址:https://www.cnblogs.com/anyuan9/p/6171549.html
Copyright © 2011-2022 走看看