這篇文章主要介紹“jdbc 數(shù)據(jù)庫的連接方法”,在日常操作中,相信很多人在jdbc 數(shù)據(jù)庫的連接方法問題上存在疑惑,小編查閱了各式資料,整理出簡(jiǎn)單好用的操作方法,希望對(duì)大家解答”jdbc 數(shù)據(jù)庫的連接方法”的疑惑有所幫助!接下來,請(qǐng)跟著小編一起來學(xué)習(xí)吧!
1.sql server 2000數(shù)據(jù)庫的連接方式:
復(fù)制代碼 代碼如下:
Connection con;
public Connection getCon(){
try{ Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");//加載驅(qū)動(dòng)程序
con=DriverManger.getConnection("jdbc:microsoft:sqlServer://localhost:1433;DatabaseName=aa","sa",""); // 試圖建立到給定數(shù)據(jù)庫 URL 的連接
}catch(ClassNotFoundException e){
e.printStackTrace();
}catch(SQLException e){
e.printStackTrace();
}
return con;
}
2.sql server 2005數(shù)據(jù)庫的連接方式:
復(fù)制代碼 代碼如下:
Connection con;
public Connection getCon(){
try{
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");//加載驅(qū)動(dòng)程序
con=DriverManger.getConnection("jdbc:microsoft:sqlServer://localhost:1433;DatabaseName=aa","sa",""); // 試圖建立到給定數(shù)據(jù)庫 URL 的連接
}catch(ClassNotFoundException e){
e.printStackTrace();
}catch(SQLException e){
e.printStackTrace();
}
return con;
}
3.oracle 數(shù)據(jù)的連接方式
復(fù)制代碼 代碼如下:
Connection con;
public Connection getCon(){
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
con=DriverManger.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:oracle","scott","tiger");
}catch(Exception e){
e.printStackTrace();
}
return con;
}
到此,關(guān)于“jdbc 數(shù)據(jù)庫的連接方法”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實(shí)踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識(shí),請(qǐng)繼續(xù)關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編會(huì)繼續(xù)努力為大家?guī)砀鄬?shí)用的文章!
網(wǎng)頁名稱:jdbc數(shù)據(jù)庫的連接方法-創(chuàng)新互聯(lián)
本文來源:http://jinyejixie.com/article0/dsigio.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供手機(jī)網(wǎng)站建設(shè)、商城網(wǎng)站、軟件開發(fā)、標(biāo)簽優(yōu)化、網(wǎng)站策劃、服務(wù)器托管
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容