av手机免费在线观看,国产女人在线视频,国产xxxx免费,捆绑调教一二三区,97影院最新理论片,色之久久综合,国产精品日韩欧美一区二区三区

java語言

Java數(shù)據(jù)庫連接代碼

時(shí)間:2025-04-07 12:52:00 java語言 我要投稿
  • 相關(guān)推薦

Java數(shù)據(jù)庫連接代碼集合

  Java數(shù)據(jù)庫連接接口(JDBC)是Java里定義的一套用于數(shù)據(jù)庫連接和操作的API的集合。下面一起跟著小編深入了解一下吧!

  有不同的數(shù)據(jù)庫廠商提供這套接口的實(shí)現(xiàn)類,對(duì)于Java程序員來說,程序員不需要關(guān)心數(shù)據(jù)庫的底層的實(shí)現(xiàn),統(tǒng)一的調(diào)用JDBC里面的抽象出來的API來完成數(shù)據(jù)庫的訪問功能,在Data access的功能和接口定義中,Java是在別的語言對(duì)數(shù)據(jù)庫的URL的描述,其他的一切也就是通過統(tǒng)一的調(diào)用來實(shí)現(xiàn)了,本文章手機(jī)了主要的數(shù)據(jù)庫廠商提供的Driver和URL,以便大家方便的對(duì)各種數(shù)據(jù)庫進(jìn)行連接的操作。

  JDBC里統(tǒng)一的使用方法:

  Class.for(jdbcDriverName);

  Connection conn=DriverManager.getConnection(url,user,password);

  這里的接口是統(tǒng)一的,不同的是每種數(shù)據(jù)庫提供的jdbcDriver和URL不同。

  MySQL:

  String Driver="com.mysql.jdbc.Driver"; //驅(qū)動(dòng)程序

  String URL="jdbc:mysql://localhost:3306/db_name"; //連接的URL,db_name為數(shù)據(jù)庫名

  String Username="username"; //用戶名

  String Password="password"; //密碼

  Class.forName(Driver).new Instance();

  Connection con=DriverManager.getConnection(URL,Username,Password);

  Microsoft SQL Server 2.0驅(qū)動(dòng)(3個(gè)jar的那個(gè)):

  String Driver="com.microsoft.jdbc.sqlserver.SQLServerDriver"; //連接SQL數(shù)據(jù)庫的方法

  String URL="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=db_name"; //db_name為數(shù)據(jù)庫名

  String Username="username"; //用戶名

  String Password="password"; //密碼

  Class.forName(Driver).new Instance(); //加載數(shù)據(jù)可驅(qū)動(dòng)

  Connection con=DriverManager.getConnection(URL,UserName,Password); //

  Microsoft SQL Server 3.0驅(qū)動(dòng)(1個(gè)jar的那個(gè)):// 老紫竹完善

  String Driver="com.microsoft.sqlserver.jdbc.SQLServerDriver"; //連接SQL數(shù)據(jù)庫的方法

  String URL="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=db_name"; //db_name為數(shù)據(jù)庫名

  String Username="username"; //用戶名

  String Password="password"; //密碼

  Class.forName(Driver).new Instance(); //加載數(shù)據(jù)可驅(qū)動(dòng)

  Connection con=DriverManager.getConnection(URL,UserName,Password); //

  Sysbase:

  String Driver="com.sybase.jdbc.SybDriver"; //驅(qū)動(dòng)程序

  String URL="jdbc:Sysbase://localhost:5007/db_name"; //db_name為數(shù)據(jù)可名

  String Username="username"; //用戶名

  String Password="password"; //密碼

  Class.forName(Driver).newInstance();

  Connection con=DriverManager.getConnection(URL,Username,Password);

  Oracle(用thin模式):

  String Driver="oracle.jdbc.driver.OracleDriver"; //連接數(shù)據(jù)庫的方法

  String URL="jdbc:oracle:thin:@loaclhost:1521:orcl"; //orcl為數(shù)據(jù)庫的SID

  String Username="username"; //用戶名

  String Password="password"; //密碼

  Class.forName(Driver).newInstance(); //加載數(shù)據(jù)庫驅(qū)動(dòng)

  Connection con=DriverManager.getConnection(URL,Username,Password);

  PostgreSQL:

  String Driver="org.postgresql.Driver"; //連接數(shù)據(jù)庫的方法

  String URL="jdbc:postgresql://localhost/db_name"; //db_name為數(shù)據(jù)可名

  String Username="username"; //用戶名

  String Password="password"; //密碼

  Class.forName(Driver).newInstance();

  Connection con=DriverManager.getConnection(URL,Username,Password);

  DB2:

  String Driver="com.ibm.db2.jdbc.app.DB2.Driver"; //連接具有DB2客戶端的Provider實(shí)例

  //String Driver="com.ibm.db2.jdbc.net.DB2.Driver"; //連接不具有DB2客戶端的Provider實(shí)例

  String URL="jdbc:db2://localhost:5000/db_name"; //db_name為數(shù)據(jù)可名

  String Username="username"; //用戶名

  String Password="password"; //密碼

  Class.forName(Driver).newInstance();

  Connection con=DriverManager.getConnection(URL,Username,Password);

  Informix:

  String Driver="com.informix.jdbc.IfxDriver";

  String URL="jdbc:Informix-sqli://localhost:1533/db_name:INFORMIXSER=myserver"; //db_name為數(shù)據(jù)可名

  String Username="username"; //用戶名

  String Password="password"; //密碼

  Class.forName(Driver).newInstance();

  Connection con=DriverManager.getConnection(URL,Username,Password);

  JDBC-ODBC:

  String Driver="sun.jdbc.odbc.JdbcOdbcDriver";

  String URL="jdbc:odbc:dbsource"; //dbsource為數(shù)據(jù)源名

  String Username="username"; //用戶名

  String Password="password"; //密碼

  Class.forName(Driver).newInstance();

  Connection con=DriverManager.getConnection(URL,Username,Password);

【Java數(shù)據(jù)庫連接代碼】相關(guān)文章:

php連接mysql數(shù)據(jù)庫代碼08-01

Java中Socket設(shè)置連接超時(shí)的代碼09-08

使用Java程序連接各種數(shù)據(jù)庫的方法08-04

java連接mysql數(shù)據(jù)庫亂碼如何解決11-13

java常用代碼07-07

使用Java程序連接各種數(shù)據(jù)庫的方法介紹09-08

JAVA代碼的基本格式07-22

Java代碼復(fù)用規(guī)則06-06

JAVA代碼優(yōu)化總結(jié)09-23