[Connector/J] [BUG] JDBC URL not handled
am 17.03.2003 13:22:11 von mattDescription:
JDBC URL are not serialized into JNDI storage, it will cause the failure
of getting connection from DataSource, if user doesn't want to use setter of
DataSource.
How-To-Repeat:
Following is the code fragment,
MysqlDataSource ds = new MysqlDataSource();
String cnctUrl =
"jdbc:mysql://127.0.0.1/test?databaseName=test&user=root&pas sword=&useUnicod
e=true&characterEncoding=UTF8";
ds.setURL(cnctUrl);
try {
ctx.rebind("mysql.jdbc", ds);
} catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
-----------------------------------------------------------
Then if you try to call getConnection() from DataSource, you will get
SQLException.
Fix:
Below is the code fragment from
com.mysql.jdbc.jdbc2.optional.MysqlDataSource, and bold&italic words are
appended code to fix this bug.
public Reference getReference()
throws NamingException {
String factoryName =
"com.mysql.jdbc.jdbc2.optional.MysqlDataSourceFactory";
Reference ref = new Reference(getClass().getName(), factoryName,
null);
ref.add(new StringRefAddr("user", getUser()));
ref.add(new StringRefAddr("password", password));
ref.add(new StringRefAddr("serverName", getServerName()));
ref.add(new StringRefAddr("port", "" + getPort()));
ref.add(new StringRefAddr("databaseName", getDatabaseName()));
ref.add(new StringRefAddr("profileSql", getProfileSql()));
ref.add(new StringRefAddr("url", getURL()));
return ref;
}
------------------------------------------------------------ ----------------
Below is the code fragment from
com.mysql.jdbc.jdbc2.optional.MysqlDataSourceFactory, and bold&italic words
are appended code to fix this bug.
public Object getObjectInstance(Object refObj, Name nm, Context ctx,
Hashtable env)
throws Exception {
Reference ref = (Reference) refObj;
String className = ref.getClassName();
if (className != null
&& (className.equals(dataSourceClassName) ||
className.equals(poolDataSourceName))) {
MysqlDataSource dataSource = null;
try {
dataSource = (MysqlDataSource)
Class.forName(className).newInstance();
} catch (Exception ex) {
throw new RuntimeException("Unable to create DataSource of "
+ "class '" + className
+ "', reason: " + ex.toString());
}
int portNumber = 3306;
portNumber =
Integer.parseInt((String)ref.get("port").getContent());
dataSource.setPort(portNumber);
dataSource.setUser((String) ref.get("user").getContent());
dataSource.setPassword((String)ref.get("password").getConten t());
dataSource.setServerName((String)
ref.get("serverName").getContent());
dataSource.setDatabaseName((String)
ref.get("databaseName").getContent());
dataSource.setURL((String)ref.get("url").getContent());
return dataSource;
} else { // We can't create an instance of the reference
return null;
}
}
Synopsis: if the JDBC URL is handled, then Driver can really get the URL
string from JNDI DataSource.
Submitter-Id:
Originator: Walter Chang, Matt Jiang
Organization: Enlighten Technology Inc.
MySQL support: [none ]
Severity: [critical ]
Priority: [high ]
Category: [J/Connector]
Class: [ sw-bug | doc-bug | change-request | support ]
Release: mysql-4.0.11a-gamma
Exectutable: [mysqld-max-nt]
Environment:
System: < Win2000 sp3>
Compiler:
Architecture:
------------------------------------------------------------ ---------
Before posting, please check:
http://www.mysql.com/manual.php (the manual)
http://lists.mysql.com/ (the list archive)
To request this thread, e-mail bugs-thread13980@lists.mysql.com
To unsubscribe, e-mail