Java連接六類數(shù)據(jù)庫技巧全攻略
小編在本文將主要為大家介紹Java與Oracle、DB2、Sql Server、Sybase、MySQL、PostgreSQL等數(shù)據(jù)庫連接的方法。
1、Oracle數(shù)據(jù)庫
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
String url="jdbc:oracle:thin:@localhost:1521:orcl";
//orcl為數(shù)據(jù)庫的SID
String user="test";
String password="test";
Connection conn= DriverManager.getConnection(url,user,password);
2、DB2數(shù)據(jù)庫
Class.forName("com.ibm.db2.jdbc.app.DB2Driver ").newInstance();
String url="jdbc:db2://localhost:5000/sample";
//sample為你的數(shù)據(jù)庫名
String user="admin";
String password="";
Connection conn= DriverManager.getConnection(url,user,password);
3、Sql Server數(shù)據(jù)庫
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=mydb";
//mydb為數(shù)據(jù)庫
String user="sa";
String password="";
Connection conn= DriverManager.getConnection(url,user,password);
4、Sybase數(shù)據(jù)庫
Class.forName("com.sybase.jdbc.SybDriver").newInstance();
String url =" jdbc:sybase:Tds:localhost:5007/myDB";
//myDB為你的數(shù)據(jù)庫名
Properties sysProps = System.getProperties();
SysProps.put("user","userid");
SysProps.put("password","user_password");
Connection conn= DriverManager.getConnection(url, SysProps);
5、MySQL數(shù)據(jù)庫
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
String url ="jdbc:mysql://localhost/myDB?user=soft&password=soft1234&useUnicode=true&characterEncoding=8859_1"
//myDB為數(shù)據(jù)庫名
Connection conn= DriverManager.getConnection(url);
6、PostgreSQL數(shù)據(jù)庫
Class.forName("org.postgresql.Driver").newInstance();
String url ="jdbc:postgresql://localhost/myDB"
//myDB為數(shù)據(jù)庫名
String user="myuser";
String password="mypassword";
Connection conn= DriverManager.getConnection(url,user,password);
以上就是Java連接各類數(shù)據(jù)庫的技巧,相信一定會(huì)對(duì)大家實(shí)現(xiàn)java連接數(shù)據(jù)庫有所幫助。
- Java插入修改刪除數(shù)據(jù)庫數(shù)據(jù)的基本方法
- 使用Java對(duì)數(shù)據(jù)庫進(jìn)行基本的查詢和更新操作
- Java程序連接數(shù)據(jù)庫的常用的類和接口介紹
- java 連接sql server2008數(shù)據(jù)庫配置
- Java中使用JDBC操作數(shù)據(jù)庫簡單實(shí)例
- Java數(shù)據(jù)導(dǎo)出功能之導(dǎo)出Excel文件實(shí)例
- Java導(dǎo)出txt文件的方法
- Java使用utf8格式保存文本文件的方法
- Java使用Preference類保存上一次記錄的方法
- Java實(shí)現(xiàn)從數(shù)據(jù)庫導(dǎo)出大量數(shù)據(jù)記錄并保存到文件的方法
相關(guān)文章
分布式系統(tǒng)下調(diào)用鏈追蹤技術(shù)面試題
這篇文章主要為大家介紹了分布式系統(tǒng)下調(diào)用鏈追蹤技術(shù)面試問題合集,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步早日升職加薪2022-03-03
linux下用renameTo方法修改java web項(xiàng)目中文件夾名稱的實(shí)例
下面小編就為大家?guī)硪黄猯inux下用renameTo方法修改java web項(xiàng)目中文件夾名稱的實(shí)例。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-06-06
springboot高并發(fā)下提高吞吐量的實(shí)現(xiàn)
這篇文章主要介紹了springboot高并發(fā)下提高吞吐量的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-11-11
Java使用poi導(dǎo)出ppt文件的實(shí)現(xiàn)代碼
Apache POI 是用Java編寫的免費(fèi)開源的跨平臺(tái)的 Java API,Apache POI提供API給Java對(duì)Microsoft Office格式檔案讀和寫的功能。本文給大家介紹Java使用poi導(dǎo)出ppt文件的實(shí)現(xiàn)代碼,需要的朋友參考下吧2021-06-06
Java單元測試Powermockito和Mockito使用總結(jié)
公司單元測試框架選用了Junit 4.12,Mock框架選用了Mockito和PowerMock,本文主要介紹了Java單元測試Powermockito和Mockito使用總結(jié),感興趣的可以了解一下2021-09-09
SpringBoot項(xiàng)目后端開發(fā)邏輯全面梳理
這篇文章主要介紹了SpringBoot項(xiàng)目后端開發(fā)邏輯全面梳理,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-11-11

