FileDocCategorySizeDatePackage
MsqlDriver.javaAPI DocExample5702Tue Jan 01 00:00:00 GMT 1980COM.imaginary.sql.msql

MsqlDriver

public class MsqlDriver extends Object implements Driver
The MsqlDriver class implements the JDBC Driver interface from the JDBC specification. A Driver is specifically concerned with making database connections via new JDBC Connection instances by responding to URL requests.
Last modified 97/04/07
version
@(#) MsqlDriver.java 1.2@(#)
author
George Reese (borg@imaginary.com)

Fields Summary
Constructors Summary
public MsqlDriver()
Constructs an MsqlDriver instance. The JDBC specification requires the driver then to register itself with the DriverManager.

exception
java.sql.SQLException an error occurred in registering

	try {
	    new MsqlDriver();
	}
	catch( SQLException e ) {
	    e.printStackTrace();
	}
    
	super();
	DriverManager.registerDriver(this);
    
Methods Summary
public booleanacceptsURL(java.lang.String url)
Returns true if the driver thinks that it can open a connection to the given URL. In this case, true is returned if and only if the subprotocol is 'msql'.

param
url The URL of the database.
return
True if this driver can connect to the given URL.
exception
java.sql.SQLException never actually is thrown

	if( url.length() < 10 ) {
	    return false;
	}
	else {
	    return url.substring(5,9).equals("msql");
	}
    
public java.sql.Connectionconnect(java.lang.String url, java.util.Properties p)
Takes a look at the given URL to see if it is meant for this driver. If not, simply return null. If it is, then go ahead and connect to the database. For the mSQL implementation of JDBC, it looks for URL's in the form of

jdbc:msql://[host_addr]:[port]/[db_name]

see
java.sql.Driver#connect
param
url the URL for the database in question
param
p the properties object
return
null if the URL should be ignored, a new Connection implementation if the URL is a valid mSQL URL
exception
java.sql.SQLException an error occurred during connection such as a network error or bad URL

	String host, database, orig = url;
	int i, port;
	
	if( url.startsWith("jdbc:") ) {
	    if( url.length() < 6 ) {
		return null;
	    }
	    url = url.substring(5);
	}
	if( !url.startsWith("msql://") ) {
	    return null;
	}
	if( url.length() < 8 ) {
	    return null;
	}
	url = url.substring(7);
	i = url.indexOf(':");
	if( i == -1 ) {
	    port = 1114;
	    i = url.indexOf('/");
	    if( i == -1 ) {
		throw new SQLException("Invalid mSQL URL: " + orig);
	    }
	    if( url.length() < i+1 ) {
		throw new SQLException("Invalid mSQL URL: " + orig);
	    }
	    host = url.substring(0, i);
	    database = url.substring(i+1);
	}
	else {
	    host = url.substring(0, i);
	    if( url.length() < i+1 ) {
		throw new SQLException("Invalid mSQL URL: " + orig);
	    }
	    url = url.substring(i+1);
	    i = url.indexOf('/");
	    if( i == -1 ) {
		throw new SQLException("Invalid mSQL URL: " + orig);
	    }
	    if( url.length() < i+1 ) {
		throw new SQLException("Invalid mSQL URL: " + orig);
	    }
	    try {
		port = Integer.parseInt(url.substring(0, i));
	    }
	    catch( NumberFormatException e ) {
		throw new SQLException("Invalid port number: " +
				       url.substring(0, i));
	    }
	    database = url.substring(i+1);
	}
	return new MsqlConnection(host, port, database, p);
    
public intgetMajorVersion()
Gives the major version for this driver as required by the JDBC specification.

see
java.sql.Driver#getMajorVersion
return
the major version

	return 1;
    
public intgetMinorVersion()
Gives the minor version for this driver as required by the JDBC specification.

see
java.sql.Driver#getMinorVersion
return
the minor version

	return 0;
    
public java.sql.DriverPropertyInfo[]getPropertyInfo(java.lang.String url, java.util.Properties info)
The getPropertyInfo method is intended to allow a generic GUI tool to discover what properties it should prompt a human for in order to get enough information to connect to a database. Note that depending on the values the human has supplied so far, additional values may become necessary, so it may be necessary to iterate though several calls to getPropertyInfo.

param
url The URL of the database to connect to.
param
info A proposed list of tag/value pairs that will be sent on connect open.
return
An array of DriverPropertyInfo objects describing possible properties. This array may be an empty array if no properties are required.
exception
java.sql.SQLException never actually thrown

	return new DriverPropertyInfo[0];
    
public booleanjdbcCompliant()
Returns information noting the fact that the mSQL database is not SQL-92 and thus cannot support a JDBC compliant implementation.

	return false;