Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #34010
| From | Kevin McMurtrie <mcmurtrie@pixelmemory.us> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Troubles with informix jdbc driver ... |
| References | <slrnnedgqn.456.avl@login.logic.tuwien.ac.at> <mcmurtrie-9B0C6C.21264114032016@news.sonic.net> <slrnneh26c.456.avl@login.logic.tuwien.ac.at> <slrnnejkme.456.avl@login.logic.tuwien.ac.at> |
| Date | 2016-03-16 22:36 -0700 |
| Message-ID | <mcmurtrie-AFC581.22363916032016@news.sonic.net> (permalink) |
| Organization | Sonic.Net |
In article <slrnnejkme.456.avl@login.logic.tuwien.ac.at>,
Andreas Leitgeb <avl@logic.at> wrote:
> Andreas Leitgeb <avl@logic.at> wrote:
> > Kevin McMurtrie <mcmurtrie@pixelmemory.us> wrote:
> >> There's too much legacy cruft and unreliable magic in DriverManager.
> >> I strongly recommend finding your driver using Class.forName(classname),
> >> creating an instance, then calling it directly through its
> >> java.sql.Driver interface.
> > I put this on my todo-list of things I'll experiment with.
> > For now, a coworker will prepare a simple class that will connect
> > to a selected db server (one of a few) and pick a row from some table
> > that will allow us to check whether the row comes from the right server.
>
> I'm now that one step further, and with that test program (which is still
> far away from an <sccee>) I can now reproduce cases of mixup from within
> eclipse debugger.
>
> Informix's Connection instance has an internal field "connInfo", which
> seems to be some kind of map that contains Properties and other stuff.
>
> Most notably, for the thread I trapped on the wrong DB, it contained a pair
> for the original (and correct) DB-URL:
> USERURL=jdbc:informix-sqli://machine:12345/dbA:informixserver=ifxserver
> but it also contained another pair:
> DATABASE=dbB
> which contained a wrong database name. This one probably got mixed in from
> some other concurrent attempt to connect to dbB on the same informixserver.
> That other thread targetting dbB got its own connection (to dbB) just fine.
> Each of the threads had got an individual instance of Connection.
>
> > It wouldn't have occurred to me to suspect DriverManager (isn't that
> > a class of the JRE, rather than of the specific driver?), so thanks
> > for that heads-up.
>
> Tomorrow I'll locally change the code to avoid DriverManager and instead
> deal with instances of IfxDriver directly - just for testing.
>
> Btw., so far I need about 5 to 20 bursts (of about 10 concurrent connection
> attempts each time) to get to see the misbehaviour happening.
>
> Thanks for caring.
Wow, I guess the Informix driver still sucks a decade later.
Here's some totally untested code to start with :)
import java.lang.ref.WeakReference;
import java.sql.Connection;
import java.sql.Driver;
import java.sql.DriverPropertyInfo;
import java.sql.SQLException;
import java.util.Properties;
public class IfxDriver implements Driver
{
private final Class<Driver> driverClass;
private final ThreadLocal<WeakReference<Driver>> driverCache = new ThreadLocal<WeakReference<Driver>>();
public IfxDriver() throws SQLException
{
try
{
driverClass = (Class<Driver>) Class.forName("com.informix.jdbc.IfxDriver");
}
catch (ClassNotFoundException e)
{
throw new SQLException("Missing driver", e);
}
}
private Driver getDriver() throws SQLException
{
final WeakReference<Driver> driverRef = driverCache.get();
Driver driver = (driverRef != null) ? driverRef.get() : null;
if (driver == null)
{
try
{
driver = driverClass.newInstance();
}
catch (InstantiationException e)
{
throw new SQLException(e.getMessage(), e.getCause());
}
catch (IllegalAccessException e)
{
throw new SQLException("Wrong driver class", e);
}
driverCache.set(new WeakReference<Driver>(driver));
}
return driver;
}
@Override
public boolean acceptsURL(String url) throws SQLException
{
return getDriver().acceptsURL(url);
}
@Override
public Connection connect(String url, Properties info) throws SQLException
{
return getDriver().connect(url, info);
}
@Override
public int getMajorVersion()
{
try
{
return getDriver().getMajorVersion();
}
catch (SQLException e)
{
throw new RuntimeException(e);
}
}
@Override
public int getMinorVersion()
{
try
{
return getDriver().getMajorVersion();
}
catch (SQLException e)
{
throw new RuntimeException(e);
}
}
@Override
public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) throws SQLException
{
return getDriver().getPropertyInfo(url, info);
}
@Override
public boolean jdbcCompliant()
{
try
{
return getDriver().jdbcCompliant();
}
catch (SQLException e)
{
throw new RuntimeException(e);
}
}
}
--
I will not see posts from astraweb, theremailer, dizum, or google
because they host Usenet flooders.
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Troubles with informix jdbc driver ... Andreas Leitgeb <avl@logic.at> - 2016-03-14 13:54 +0000
Re: Troubles with informix jdbc driver ... Marcel Mueller <news.5.maazl@spamgourmet.org> - 2016-03-14 21:23 +0100
Re: Troubles with informix jdbc driver ... Andreas Leitgeb <avl@logic.at> - 2016-03-14 21:30 +0000
Re: Troubles with informix jdbc driver ... Arne Vajhøj <arne@vajhoej.dk> - 2016-03-14 18:16 -0400
Re: Troubles with informix jdbc driver ... Marcel Mueller <news.5.maazl@spamgourmet.org> - 2016-03-15 21:57 +0100
Re: Troubles with informix jdbc driver ... Arne Vajhøj <arne@vajhoej.dk> - 2016-03-15 21:18 -0400
Re: Troubles with informix jdbc driver ... Andreas Leitgeb <avl@logic.at> - 2016-03-15 22:25 +0000
Re: Troubles with informix jdbc driver ... Arne Vajhøj <arne@vajhoej.dk> - 2016-03-15 21:25 -0400
Re: Troubles with informix jdbc driver ... Kevin McMurtrie <mcmurtrie@pixelmemory.us> - 2016-03-14 21:26 -0700
Re: Troubles with informix jdbc driver ... Andreas Leitgeb <avl@logic.at> - 2016-03-15 22:09 +0000
Re: Troubles with informix jdbc driver ... Andreas Leitgeb <avl@logic.at> - 2016-03-16 21:37 +0000
Re: Troubles with informix jdbc driver ... Kevin McMurtrie <mcmurtrie@pixelmemory.us> - 2016-03-16 22:36 -0700
Re: Troubles with informix jdbc driver ... -- workaround found Andreas Leitgeb <avl@logic.at> - 2016-03-17 17:23 +0000
Re: Troubles with informix jdbc driver ... -- workaround found Andreas Leitgeb <avl@logic.at> - 2016-03-18 11:13 +0000
csiph-web