如何检验jsp连接oracle数据库,jsp 连接Oracle 数据库四种方法

本文提供了一个使用Java连接Oracle数据库的示例代码,通过加载Oracle JDBC驱动并建立数据库连接,展示了如何处理可能出现的异常。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

package dbbean;

import java.sql.*;

public class contactbean{

private connection con; //初始化连接。

public contactbean() {

try  {   class.forname("oracle.jdbc.driver.oracledriver").newinstance();

string url="jdbc:oracle:thin:@localhost:1521:hcm";

string user="jsp教程dev";

string password="19831007";

con= drivermanager.getconnection(url,user,password);

}

catch (instantiationexception e)

{   // todo auto-generated catch block

e.printstacktrace();

} catch (illegalaccessexception e)

{   // todo auto-generated catch block

e.printstacktrace();

}

catch(classnotfoundexception e)

{

system.out.println("driver not found!");

con=null;

}

catch(sqlexception e)

{    con=null;   }

}

//代码二

class.forname("oracle.jdbc.driver.oracledriver").newinstance();?

string?url="jdbc:oracle:thin:@localhost:1521:orcl";?

//orcl为你的数据库教程的sid?

string?user="scott";?

string?password="tiger";?

connection?conn=?drivermanager.getconnection(url,user,password);?

//

class.forname("oracle.jdbc.driver.oracledriver").newinstance();?

string?url="jdbc:oracle:thin:@localhost:1521:orcl";?

//orcl为你的数据库的sid?

string?user="scott";?

string?password="tiger";?

connection?conn=?drivermanager.getconnection(url,user,password);?

statement?stmt=conn.createstatement(resultset.type_scroll_sensitive,resultset.concur_updatable

%>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值