potentially unresolved symbols in mysql connector j

Erik Poupaert erik.poupaert@chello.be
Mon Jun 16 22:02:00 GMT 2003


By the way, it's again the same story with jdbc as with other statically
linked libraries. The linker won't include symbols that are
only dynamically referenced through reflection. For example,
class.forName(...).getInstance(), won't cause the inclusion of the class
instantiated.

There are several alternatives to handling this issue:

(1) use the whole archive approach;

(2) compile dynamically;

(3) add a statical reference to the class:

private static final Class MYSQL_CONNECTOR=com.mysql.jdbc.Driver.class;

This reference will trigger the inclusion of the Driver class. And since
the driver class directly references the Connection class, which
references the ResultSet class, and so on ... the whole connector comes
along.

(4) avoid reflection altogether. That's what I do. 

For example:

...
	protected com.mysql.jdbc.Driver mDriver;

		mDriver=new com.mysql.jdbc.Driver();
		mProperties = new Properties();
		mProperties.setProperty("user", mRdbUser);
		mProperties.setProperty("password", mRdbPwd);
		mProperties.setProperty("autoReconnect","TRUE");

	public Connection getConnection() throws SQLException
	{
		if(mConnection==null)
		{
			mUrl="jdbc:mysql://" + mRdbServer + "/" + mRdbName;
			System.out.println("Connecting to mysql on " + mUrl +
					" as user '" + mRdbUser + "' ...");
			mConnection=mDriver.connect(mUrl,mProperties);
			System.out.println("... connection to mysql opened.");
		}
		return mConnection;
	}
...

You could say that this approach "marries" your application to this
particular rdbms type...

But, if you think of it, you're probably married to it anyway; if only
because you're undoubtedly already using it's particular dialectic
version of SQL.

I try to avoid getting married (and keep it to casual things)  by
generating most SQL that I use, but still, the remainder still manages
to be quite mysql-specific...

-- 



More information about the Java mailing list