Java如何获取JDBC驱动程序属性信息?
下面的示例向您展示如何获取有关相应JDBC驱动程序可能的属性的信息。
package org.nhooo.example.jdbc;
import java.sql.*;
public class DriverPropertyInfoDemo {
private static final String URL = "jdbc:mysql://localhost/nhooo";
public static void main(String[] args) {
try {
//获取有关此属性的信息
//司机。
Driver driver = DriverManager.getDriver(URL);
DriverPropertyInfo[] props = driver.getPropertyInfo(URL, null);
for (DriverPropertyInfo info : props) {
System.out.println("Name : " + info.name);
System.out.println("Description: " + info.description);
System.out.println("Value : " + info.value);
System.out.println("-----------------------------------");
String[] choices = info.choices;
if (choices != null) {
StringBuilder sb = new StringBuilder("Choices : ");
for (String choice : choices) {
sb.append(choice).append(",");
}
System.out.println(sb.toString());
}
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}上面的代码片段的示例结果:
Name : HOST Description: Hostname of MySQL Server Value : localhost ----------------------------------- Name : PORT Description: Port number of MySQL Server Value : 3306 ----------------------------------- Name : DBNAME Description: Database name Value : nhooo ----------------------------------- Name : allowLoadLocalInfile Description: Should the driver allow use of 'LOAD DATA LOCAL INFILE...' (defaults to 'true'). Value : true Choices : true,false,yes,no, -----------------------------------
Maven依赖
<!-- https://search.maven.org/remotecontent?filepath=mysql/mysql-connector-java/8.0.17/mysql-connector-java-8.0.17.jar -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.17</version>
</dependency>热门推荐
10 对患者生日祝福语简短
11 结婚祝福语简短装备
12 周岁祝福语学生文案简短
13 订婚领证祝福语简短精辟
14 导师获奖祝福语大全简短
15 新婚购房祝福语简短精辟
16 牛年祝福语简短的爱人
17 送芒果的祝福语简短
18 送给学长毕业祝福语简短