?? nonregisteringdriver.java
字號:
DriverPropertyInfo prepStmtCacheSqlLimit = new DriverPropertyInfo("prepStmtCacheSqlLimit", info.getProperty("prepStmtCacheSqlLimit", "256")); prepStmtCacheSqlLimit.required = false; prepStmtCacheSqlLimit.description = "If prepared statement caching is enabled, " + "what's the largest SQL the driver will cache the parsing for? (in chars, default is '256')"; DriverPropertyInfo useUnbufferedInput = new DriverPropertyInfo("useUnbufferedInput", info.getProperty("useUnbufferedInput", "true")); useUnbufferedInput.required = false; useUnbufferedInput.description = "Don't use BufferedInputStream for reading data from the server true/false (default is 'true')"; DriverPropertyInfo[] dpi = { hostProp, portProp, dbProp, userProp, passwordProp, autoReconnect, maxReconnects, initialTimeout, profileSql, socketTimeout, useSSL, paranoid, useHostsInPrivileges, interactiveClient, useCompression, useTimezone, serverTimezone, connectTimeout, secondsBeforeRetryMaster, queriesBeforeRetryMaster, useStreamLengthsInPrepStmts, continueBatchOnError, allowLoadLocalInfile, strictUpdates, ignoreNonTxTables, reconnectAtTxEnd, alwaysClearStream, cachePrepStmts, prepStmtCacheSize, prepStmtCacheSqlLimit, useUnbufferedInput }; return dpi; } /** * Typically, drivers will return true if they understand the subprotocol * specified in the URL and false if they don't. This driver's protocols * start with jdbc:mysql: * * @param url the URL of the driver * * @return true if this driver accepts the given URL * * @exception java.sql.SQLException if a database-access error occurs * * @see java.sql.Driver#acceptsURL */ public boolean acceptsURL(String url) throws java.sql.SQLException { return (parseURL(url, null) != null); } /** * Try to make a database connection to the given URL. The driver should * return "null" if it realizes it is the wrong kind of driver to connect * to the given URL. This will be common, as when the JDBC driverManager * is asked to connect to a given URL, it passes the URL to each loaded * driver in turn. * * <p> * The driver should raise an java.sql.SQLException if it is the right * driver to connect to the given URL, but has trouble connecting to the * database. * </p> * * <p> * The java.util.Properties argument can be used to pass arbitrary string * tag/value pairs as connection arguments. * </p> * * <p> * My protocol takes the form: * <PRE> * jdbc:mysql://host:port/database * </PRE> * </p> * * @param url the URL of the database to connect to * @param info a list of arbitrary tag/value pairs as connection arguments * * @return a connection to the URL or null if it isnt us * * @exception java.sql.SQLException if a database access error occurs * @throws SQLException DOCUMENT ME! * * @see java.sql.Driver#connect */ public java.sql.Connection connect(String url, Properties info) throws java.sql.SQLException { Properties props = null; if ((props = parseURL(url, info)) == null) { return null; } else { try { Connection newConn = new com.mysql.jdbc.Connection(host(props), port(props), props, database(props), url, this); return (java.sql.Connection) newConn; } catch (SQLException sqlEx) { // Don't wrap SQLExceptions, throw // them un-changed. throw sqlEx; } catch (Exception ex) { throw new SQLException( "Cannot load connection class because of underlying exception: '" + ex.toString() + "'.", SQLError.SQL_STATE_UNABLE_TO_CONNECT_TO_DATASOURCE); } } } // // return the database name property // /** * Returns the database property from <code>props</code> * * @param props the Properties to look for the database property. * * @return the database name. */ public String database(Properties props) { return props.getProperty("DBNAME"); } /** * Returns the hostname property * * @param props the java.util.Properties instance to retrieve the hostname * from. * * @return the hostname */ public String host(Properties props) { return props.getProperty("HOST", "localhost"); } /** * Report whether the driver is a genuine JDBC compliant driver. A driver * may only report "true" here if it passes the JDBC compliance tests, * otherwise it is required to return false. JDBC compliance requires * full support for the JDBC API and full support for SQL 92 Entry Level. * * <p> * MySQL is not SQL92 compliant * </p> * * @return is this driver JDBC compliant? */ public boolean jdbcCompliant() { return false; } /** * Constructs a new DriverURL, splitting the specified URL into its * component parts * * @param url JDBC URL to parse * @param defaults Default properties * * @return Properties with elements added from the url * * @exception java.sql.SQLException */ public Properties parseURL(String url, Properties defaults) throws java.sql.SQLException { Properties urlProps = (defaults != null) ? defaults : new Properties(defaults); if (url == null) { return null; } else { /* * Parse parameters after the ? in the URL and remove * them from the original URL. */ int index = url.indexOf("?"); if (index != -1) { String paramString = url.substring(index + 1, url.length()); url = url.substring(0, index); StringTokenizer queryParams = new StringTokenizer(paramString, "&"); while (queryParams.hasMoreTokens()) { StringTokenizer vp = new StringTokenizer(queryParams .nextToken(), "="); String param = ""; if (vp.hasMoreTokens()) { param = vp.nextToken(); } String value = ""; if (vp.hasMoreTokens()) { value = vp.nextToken(); } if ((value.length() > 0) && (param.length() > 0)) { urlProps.put(param, value); } } } } if (!StringUtils.startsWithIgnoreCase(url, "jdbc:mysql://")) { return null; } url = url.substring(13); String hostStuff = null; int slashIndex = url.indexOf("/"); if (slashIndex != -1) { hostStuff = url.substring(0, slashIndex); if ((slashIndex + 1) < url.length()) { urlProps.put("DBNAME", url.substring((slashIndex + 1), url.length())); } } else { return null; } if ((hostStuff != null) && (hostStuff.length() > 0)) { urlProps.put("HOST", hostStuff); } return urlProps; } /** * Returns the port number property * * @param props the properties to get the port number from * * @return the port number */ public int port(Properties props) { return Integer.parseInt(props.getProperty("PORT", "3306")); } // // return the value of any property this driver knows about // /** * Returns the given property from <code>props</code> * * @param name the property name * @param props the property instance to look in * * @return the property value, or null if not found. */ public String property(String name, Properties props) { return props.getProperty(name); } /** * Parses hostPortPair in the form of [host][:port] into an array, with * the element of index HOST_NAME_INDEX being the host (or null if not * specified), and the element of index PORT_NUMBER_INDEX being the port * (or null if not specified). * * @param hostPortPair host and port in form of of [host][:port] * * @return array containing host and port as Strings * * @throws SQLException if a parse error occurs */ protected static String[] parseHostPortPair(String hostPortPair) throws SQLException { int portIndex = hostPortPair.indexOf(":"); String[] splitValues = new String[2]; String hostname = null; if (portIndex != -1) { if ((portIndex + 1) < hostPortPair.length()) { String portAsString = hostPortPair.substring(portIndex + 1); hostname = hostPortPair.substring(0, portIndex); splitValues[HOST_NAME_INDEX] = hostname; splitValues[PORT_NUMBER_INDEX] = portAsString; } else { throw new SQLException("Must specify port after ':' in connection string", SQLError.SQL_STATE_INVALID_CONNECTION_ATTRIBUTE); } } else { splitValues[HOST_NAME_INDEX] = hostPortPair; splitValues[PORT_NUMBER_INDEX] = null; } return splitValues; } /** * Gets the drivers major version number * * @return the drivers major version number */ static int getMajorVersionInternal() { return safeIntParse("3"); } /** * Get the drivers minor version number * * @return the drivers minor version number */ static int getMinorVersionInternal() { return safeIntParse("0"); } private static int safeIntParse(String intAsString) { try { return Integer.parseInt(intAsString); } catch (NumberFormatException nfe) { return 0; } }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -