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();
        }

    }


  • 相关阅读:
    vue-cli项目中使用vw——相比flexible更原生的移动端解决方案
    android shap画圆(空心圆、实心圆)
    Android四大组件——Activity跳转动画、淡出淡入、滑出滑入、自定义退出进入
    HDU 3980 Paint Chain (sg函数)
    HDU 3951 Coin Game (简单博弈)
    HDU 1850 Being a Good Boy in Spring Festival (Nim博弈)
    HDU 3389 Game (阶梯博弈)
    HDU 3032 Nim or not Nim? (sg函数)
    HDU 1907 John (Nim博弈)
    HDU 4638 Group (线段树 | 树状数组 + 离线处理)
  • 原文地址:https://www.cnblogs.com/anyuan9/p/6171549.html
Copyright © 2011-2022 走看看