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("\nOperate Over!");

    }

    

    public static void main(String args[])throws Exception{

          new OracleConnectionDemo();

    }

}

java.sql.SQLException:指定了无效的 Oracle URL的更多相关文章

  1. [转载]“java.sql.SQLException:指定了无效的 Oracle URL”

    原文地址:"java.sql.SQLException:指定了无效的 Oracle URL"作者:康愚 昨天晚上用MyEclipse连接Oracle,出现了" java. ...

  2. java.sql.SQLException: 关闭的连接 解决办法

    程序如果长时间不进行数据库操作,那么数据源中的 Connection 很可能已经断开.其原因有可能是防火墙,或者连接的数据库设置的超时时间.这里使用的是 C3P0 连接 oracle 数据库,引起的异 ...

  3. oracle: jdbcTypeForNull configuration property. Cause: java.sql.SQLException: 无效的列类型: 1111

    https://www.cnblogs.com/mmlw/p/5808072.html org.mybatis.spring.MyBatisSystemException: nested except ...

  4. hibernate连接oracle12c数据库报:java.sql.SQLException: ORA-01017: 用户名/口令无效; 登录被拒绝。(用户名/口令在oracle客户端以及cmd命令都能登入)

    报错信息: 2017-09-22 15:40:07,354 WARN [org.hibernate.cfg.SettingsFactory] - Could not obtain connection ...

  5. java.sql.SQLException: 对只转发结果集的无效操作: last

    出错代码如下:static String u = "user";static String p = "psw";static String url = &quo ...

  6. Error querying database. Cause: java.sql.SQLException: ORA-01745: 无效的主机/绑定变量名

    今天调试程序是遇到了,下面的一个问题.我将对应的SQL语句拿到Toad下也能正常的执行,感觉有点莫名其妙,根据异常信息的提示查看对应的映射结果集也没发现错误,然后百度了一下,也有许多朋友也遇到过这样的 ...

  7. 在mybatis中使用存储过程报错java.sql.SQLException: ORA-06550: 第 1 行, 第 7 列: PLS-00905: 对象 USER1.HELLO_TEST 无效 ORA-06550: 第 1 行, 第 7 列:

    hello_test是我的存储过程的名字,在mapper.xml文件中是这么写的 <select id="getPageByProcedure" statementType= ...

  8. mybatis项目报错:java.sql.SQLException: ORA-00911: 无效字符 解决方法

    如果你用java写程序访问数据库,出现这个问题:java.sql.SQLException: ORA-00911: 无效字符 at oracle.jdbc.driver.DatabaseError.t ...

  9. java.sql.SQLException: [Microsoft][ODBC 驱动程序管理器] 在指定的 DSN 中,驱动程序和应用程序之间的体系结构不匹配

    今天把sql server 2008 r2装了起来,64位的,然后就迫不及待地体验连接数据库的操作,编程语言是java.我一开始学了一种非常老的连接方式,使用JDBC-ODBC桥.初次使用不太熟练,所 ...

随机推荐

  1. JavaScript 类私有方法的实现

    一:将私有方法移出模块,因为模块内部的所有方法都是对外可见的. class Widget { foo (baz) { bar.call(this, baz); } // ... } function ...

  2. 获得HttpServletResponse及其他对象

    下面只列出获得 HttpServletResponse 对象的方法,获得 HttpServletRequest 对象方法类似. 在struts1.x Action类的execute方法中,有四个参数, ...

  3. structured sparsity model

    Data representation往往基于如下最小化问题:         (1) 其中X是观测到的数据的特征矩阵,D是字典,Z是字典上的描述.约束项和使得字典dictionary和描述code具 ...

  4. [React] React Router: Nested Routes

    Since react-router routes are components, creating nested routes is as simple as making one route a ...

  5. [React Testing] JSX error diffs -- expect-jsx library

    When writing React component tests, it can be hard to decipher the error diffs of broken tests, sinc ...

  6. CentOS6.7 下安装git

    在CentOS5的时代,由于yum源中没有git,所以需要预先安装一系列的依赖包.但在CentOS6的yum源中已经有git的版本了,可以直接使用yum源进行安装. $ sudo yum instal ...

  7. 根据id查询数据(向前台返回json格式的数据)

    /** *@description 根据主键查询Bean */ @RequestMapping(value="/getBean/{getId}") public void getB ...

  8. AngularJs练习Demo19 Resource

    @{ Layout = null; } <!DOCTYPE html> <html> <head> <meta name="viewport&quo ...

  9. hdu5398 GCD Tree(lct)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud GCD Tree Time Limit: 5000/2500 MS (Java/O ...

  10. uva 371 - Ackermann Functions

    #include <cstdio> int main() { long int F, S, I, Count, Value, Max, J; while(scanf("%ld % ...