Bug in JVM causing problems with MessageTranslator
От | Darin Ohashi |
---|---|
Тема | Bug in JVM causing problems with MessageTranslator |
Дата | |
Msg-id | F17255C2B596D3119A5600508B44FA68052EB8C1@courier.maplesoft.on.ca обсуждение исходный текст |
Список | pgsql-jdbc |
This code works fine under linux and other unix platforms, but it fails on windows (2000). It looks like the error message resource (which is loaded by the Message Translator singleton) is not loaded if the jdbc classes are loaded with a class loader other than the default. This behaviour looks like a bug in jdk version (1.4.0) that I am using, however I though you might be interested (espeically if this still occurs with new jdks). For this to "work" pg73jdbc3.jar should not be in the classpath. import java.sql.*; import java.util.Properties; import java.net.URLClassLoader; import java.net.URL; class SQLTest { public static void main( String args[] ) throws Exception { Driver driver; Connection con; Properties prop; URL urls[]; URLClassLoader loader; urls = new URL[1]; driver = null; try { urls[0] = new URL( "file://c:/path/to/pg73jdbc3.jar" ); loader = new URLClassLoader( urls ); driver = (Driver)loader.loadClass( "org.postgresql.Driver" ).newInstance(); } catch ( Exception e ) { System.out.println( e.toString() ); System.exit( 0 ); } //driver = (Driver)Class.forName( "org.postgresql.Driver" ).newInstance(); prop = new Properties(); prop.setProperty( "user", "test" ); prop.setProperty( "password", "test" ); con = driver.connect( "jdbc:postgresql://somehost/TestDB", prop ); try { con.setTransactionIsolation( Connection.TRANSACTION_READ_UNCOMMITTED ); } catch ( Exception e ) { System.out.println( e.getMessage() ); throw e; } } } It produces this output: postgresql.con.isolevel Exception in thread "main" postgresql.con.isolevel at org.postgresql.jdbc1.AbstractJdbc1Connection.setTransactionIsolation( AbstractJdbc1Connection.java:1124) at SQLTest.main(SQLTest.java:45) It looks like ResourceBundle uses the default class loader when trying to load the resources, thus it does not find them. I think it should be using the class loader that was used to load the ResourceBundle, (which has access to the correct jar file). Does anyone know of a good work around for this problem? My current plan is to preemptively load MessageTranslator when I load Driver. That should work, but its a bit ugly. Darin
В списке pgsql-jdbc по дате отправления: