这个压缩包里的都是超级经典的java例子

源代码在线查看: getpropinfo.htm

软件大小: 2381 K
上传用户: sinoarts
关键词: java 超级
下载地址: 免注册下载 普通下载 VIP

相关代码

				
				
				
				Listing All Available Parameters for Creating a JDBC Connection (Java Developers Almanac Example)
				
				
				
				
				
				
				
				
				
				
				
				
				
				
				
				
				
				
				
				
				
				The Java Developers Almanac 1.4
				
				        Order this book from Amazon.
				    
				
				
				
				
				
				
				
				
				
				
				
				
				
								google_ad_client = "pub-6001183370374757";
				google_ad_width = 120;
				google_ad_height = 600;
				google_ad_format = "120x600_as";
				google_ad_channel = "4777242811";
				google_ad_type = "text_image";
				google_color_border = "FFFFFF";
				google_color_bg = "FFFFFF";
				google_color_link = "6666CC";
				google_color_url = "6666CC";
				google_color_text = "000000";
				//-->   
				
				Home
				    >
				    List of Packages
				    >
				
				    
				    java.sql
				         [73 examples]
				    
				        >
				        Connections
				             [10 examples]
				            
				
				  e238. Listing All Available Parameters for Creating a JDBC Connection
				
				
				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
				
				
				
				
				e235. 
				    Connecting to an Oracle Database
				
				
				
				e236. 
				    Connecting to a MySQL Database
				
				
				
				e237. 
				    Connecting to a SQLServer Database
				
				
				
				e239. 
				    Determining If a Database Supports Transactions
				
				
				
				e240. 
				    Committing and Rolling Back Updates to a Database
				
				
				
				e241. 
				    Handling a SQL Exception
				
				
				
				e242. 
				    Determining If a SQL Warning Occurred
				
				
				
				e243. 
				    Getting the Driver of a Connection
				
				
				
				e244. 
				    Setting the Number of Rows to Prefetch When Executing a SQL Query
				
				
				
				
				
				
				
				
				        See also: 
				
				    Batching
				  
				
				
				    Database Meta Data
				  
				
				
				    Deleting Data
				  
				
				
				    Drivers
				  
				
				
				    Importing and Exporting
				  
				
				
				    Inserting and Updating Data
				  
				
				
				    Oracle OBJECTs
				  
				
				
				    Oracle VARRAYs
				  
				
				
				    Procedures and Functions
				  
				
				
				    Retrieving Data
				  
				
				
				    Scrollable Result Sets
				  
				
				
				    Tables
				  
				
				
				    Updatable Result Sets
				  
				
				
				
				
				
				
				
				
				
				© 2002 Addison-Wesley.
				   
				
				
				
				
				
				
				
				
							

相关资源