[Connector/J] [BUG] JDBC URL not handled

[Connector/J] [BUG] JDBC URL not handled

am 17.03.2003 13:22:11 von matt

Description:
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

Re: [Connector/J] [BUG] JDBC URL not handled

am 17.03.2003 14:32:00 von Mark Matthews

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Matt wrote:
>
> Description:
> 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;
> }
> }

Thank you for your bug report. This is being fixed for Connector/J 3.0.x
and 3.1.x.

-Mark


- --
MySQL 2003 Users Conference -> http://www.mysql.com/events/uc2003/

For technical support contracts, visit https://order.mysql.com/?ref=mmma

__ ___ ___ ____ __
/ |/ /_ __/ __/ __ \/ / Mark Matthews
/ /|_/ / // /\ \/ /_/ / /__ MySQL AB, Full-Time Developer - JDBC/Java
/_/ /_/\_, /___/\___\_\___/ Flossmoor (Chicago), IL USA
<___/ www.mysql.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.1.90 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQE+dc5QtvXNTca6JD8RAjENAJ9bUr5VtAWTxvDedu3/aUK1AwM4QgCf cFRo
N/6aThCRSenQUWn49d5UQ+s=
=NrIl
-----END PGP SIGNATURE-----


------------------------------------------------------------ ---------
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-thread13982@lists.mysql.com
To unsubscribe, e-mail