java jdbc oracle url,使用JDBC连接Oracle数据库的URL字符串格式

I'm a newbie to Java-related web development, and I can't seem to get a simple program with JDBC working. I'm using off-the-shelf Oracle 10g XE and the Eclipse EE IDE. From the books and web pages I've checked so far, I've narrowed the problem down to either an incorrectly written database URL or a missing JAR file. I'm getting the following error:

java.sql.SQLException: No suitable driver found for jdbc:oracle://127.0.0.1:8080

with the following code:

import java.sql.*;

public class DatabaseTestOne {

public static void main(String[] args) {

String url = "jdbc:oracle://127.0.0.1:8080";

String username = "HR";

String password = "samplepass";

String sql = "SELECT EMPLOYEE_ID FROM EMPLOYEES WHERE LAST_NAME='King'";

Connection connection;

try {

connection = DriverManager.getConnection(url, username, password);

Statement statement = connection.createStatement();

System.out.println(statement.execute(sql));

connection.close();

} catch (SQLException e) {

System.err.println(e);

}

}

}

What is the proper format for a database URL, anyways? They're mentioned a lot but I haven't been able to find a description.

EDIT (the resolution):

Based on duffymo's answer, I got ojdbc14.jar from Oracle's download site and dropped it in the Eclipse project's Referenced Libraries. Then I changed the start of the code to

...

// jdbc:oracle:thin:@::

String url = "jdbc:oracle:thin:@GalacticAC:1521:xe";

...

and it worked.

解决方案

Look here.

Your URL is quite incorrect. Should look like this:

url="jdbc:oracle:thin:@localhost:1521:orcl"

You don't register a driver class, either. You want to download the thin driver JAR, put it in your CLASSPATH, and make your code look more like this.

UPDATE: The "14" in "ojdbc14.jar" stands for JDK 1.4. You should match your driver version with the JDK you're running. I'm betting that means JDK 5 or 6.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值