JDBC数据库连接的驱动名称及URL

  • 格式:txt
  • 大小:2.00 KB
  • 文档页数:1

在需要通过JDBC链接数据库系统时,我们需要知道一下信息:

驱动程序类名:一个继承java.sql.Driver接口的类名,JDBC驱动程序管理器需要加载这个类来处理数据库驱动程序。

数据库URL:一个字符串,该字符串包含关于数据库连接的信息和其他配置属性。这个字符串有自己的格式,不同数据库之间存在不同。



1. MySQL

驱动程序类名:com.mysql.jdbc.Driver

数据库URL格式:

jdbc:mysql://[host][,failoverhost...][:port]/[database][?propertyName1][=propertyValue1][&propertyName2][=propertyValue2]...

例子:

jdbc:mysql://localhost:3306 /test

jdbc:mysql://localhost:3306 /test?user=uncletoo&password =123



2. SQL Server

驱动程序类名:com.microsoft.sqlserver.jdbc.SQLServerDriver

数据库URL格式:

jdbc:sqlserver://[serverName[\instanceName][:portNumber]][;property=value[;property=value]]

例子:

jdbc:sqlserver://localhost;integratedSecurity=true;

jdbc:sqlserver://localhost\\sqlexpress;integratedSecurity=true

jdbc:sqlserver://localhost\\sqlexpress;user=uncletoo;password=123



3. Oracle

驱动程序类名:oracle.jdbc.OracleDriver

数据库URL格式:

jdbc:oracle::@

jdbc:oracle::/@ where drivertype can be thin, oci or kprb.

例子:

jdbc:oracle:thin:@localhost:1521:testdb

jdbc:oracle:thin:root/secret@localhost:1521:testdb

jdbc:oracle:oci:@hoststring

jdbc:oracle:oci:@localhost:1521:testdb

jdbc:oracle:oci:root/secret@hoststring>

Jdbc:oracle:oci:root/secret@localhost:1521:testdb



4. PostgreSQL

驱动程序类名:org.postgresql.Driver

数据库URL格式:

jdbc:postgresql:database

jdbc:postgresql://host/database

jdbc:postgresql://host:port/database

例子:

jdbc:postgresql:testdb

jdbc:postgresql://localhost/testdb

jdbc:postgresql://localhost:5432/testdb



5. SQLite

驱动程序类名:org.sqlite.JDBC

数据库URL格式:jdbc:sqlite:database_file_path

例子:

jdbc:sqlite:sample.db

jdbc:derby:D:/work/project/data.db



注意:从JDBC 4.0开始,不再需要显式地加载驱动程序类,所以你不需要关心驱动程序类的名称。

下载文档原格式

  / 1
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。