⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 e238. listing all available parameters for creating a jdbc connection.txt

📁 这里面包含了一百多个JAVA源文件
💻 TXT
字号:
Driver.getPropertyInfo() returns a list of all available properties that can be supplied when using the driver to create a JDBC connection. This list can be displayed to the user. 
    try {
        // Load the driver
        String driverName = "org.gjt.mm.mysql.Driver"; // MySQL MM JDBC driver
        Class.forName(driverName);
    
        // Get the Driver instance
        String url = "jdbc:mysql://a/b";
        Driver driver = DriverManager.getDriver(url);
    
        // Get available properties
        DriverPropertyInfo[] info = driver.getPropertyInfo(url, null);
        for (int i=0; i<info.length; i++) {
            // Get name of property
            String name = info[i].name;
    
            // Is property value required?
            boolean isRequired = info[i].required;
    
            // Get current value
            String value = info[i].value;
    
            // Get description of property
            String desc = info[i].description;
    
            // Get possible choices for property; if null, value can be any string
            String[] choices = info[i].choices;
        }
    } catch (ClassNotFoundException e) {
       // Could not find the database driver
    } catch (SQLException e) {
    }

Here's the property values for the MySql driver: 
    Name(isRequired): Description
        default: default value
        choices: ...
    
    HOST(true): Hostname of MySQL Server
        default: a
    
    PORT(false): Port number of MySQL Server
        default: 3306
    
    DBNAME(false): Database name
        default: b
    
    user(true): Username to authenticate as
        default: null
    
    password(true): Password to use for authentication
        default: null
    
    autoReconnect(false): Should the driver try to re-establish bad connections?
        default: false
        choices: true, false
    
    maxReconnects(false): Maximum number of reconnects to attempt if autoReconnect is true
        default: 3
    
    initialTimeout(false): Initial timeout (seconds) to wait between failed connections
        default: 2

 Related Examples 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -