当前位置:文档之家› JDBC数据库连接的驱动名称及URL

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

在需要通过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开始,不再需要显式地加载驱动程序类,所以你不需要关心驱动程序类的名称。

相关主题
文本预览
相关文档 最新文档