[英]Unable connect to Oracle 11g using JDBC - Invalid oracle URL specified
I'm struggling with establishing connection to my database using JDBC. 我正在努力使用JDBC建立与数据库的连接。 I've done already all necessary things mentioned in documentation.
我已经完成了文档中提到的所有必要的事情。
I wrote few basic lines with try/catch block to establish connection: 我用try / catch块写了几个基本的行来建立连接:
Connection myConn = DriverManager.getConnection("jdbc:oracle:thin@localhost:1521:xe", "system", "somepass"); Statement myStat = myConn.createStatement(); ResultSet myRe = myStat.executeQuery("SELECT * from PATIENTS"); while(myRe.next()){ System.out.println(myRe.getString("LAST_NAME")); } myConn.close(); myRe.close();
But after running my code i receive error "Invalid Oracle URL specified". 但在运行我的代码后,我收到错误“指定了无效的Oracle URL”。 Everything looks fine but I am just starting with JDBC.. Did I miss something?
一切都很好,但我刚刚开始使用JDBC ..我错过了什么吗?
You are missing a colon - use 你错过了冒号 - 使用
jdbc:oracle:thin:@localhost:1521:xe
^
instead of 代替
jdbc:oracle:thin@localhost:1521:xe
^^^
as the connection string. 作为连接字符串。
See also https://docs.oracle.com/cd/E11882_01/appdev.112/e13995/oracle/jdbc/OracleDriver.html 另见https://docs.oracle.com/cd/E11882_01/appdev.112/e13995/oracle/jdbc/OracleDriver.html
... Where the URL is of the form:
... URL的格式如下:
jdbc:oracle:<drivertype>:@<database>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.