一聚教程网:一个值得你收藏的教程网站

热门教程

jsp 连接Oracle 数据库四种方法

时间:2022-06-29 03:15:16 编辑:袖梨 来源:一聚教程网

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
%>

热门栏目