java语言测试连接oracle数据库 package com.linuxidc.jdbc; import java.sql.connection;import java.sql.drivermanager;/** * 测
java语言测试连接oracle数据库
package com.linuxidc.jdbc;
import java.sql.connection;
import java.sql.drivermanager;
/**
* 测试连接oracle数据库
* @author wpc
*
*/
public class jdbcsuccess {
//驱动,url,用户名,密码
private static final string driver = oracle.jdbc.driver.oracledriver;
private static final string url = jdbc:oracle:thin:@localhost:1521:orcl;
private static final string username = scott;
private static final string password = 929118;
public static connection getconnection() {
connection connection = null;
try {
// 加 载驱动
class.forname(driver);
// 通过驱动管理类获取数据库连接
connection = drivermanager.getconnection(url, username, password);
// 关闭连接
connection.close();
} catch (classnotfoundexception e) {
e.printstacktrace();
} catch (exception e) {
e.printstacktrace();
}
return connection;
}
// 测试oracle连接是否成功
public static void main(string[] args) {
connection connection = jdbcsuccess.getconnection();
if (connection != null) {
system.out.println(连接oracle数据库成功: + connection);
} else {
system.out.println(连接oracle数据库失败!!!);
}
}
}
本文永久更新链接地址:
,