problem in connetting using reflection

Поиск
Список
Период
Сортировка
От Giuseppe Sacco
Тема problem in connetting using reflection
Дата
Msg-id 1081642610.713.23.camel@eppesuig3
обсуждение исходный текст
Ответы Re: problem in connetting using reflection
Re: problem in connetting using reflection
Список pgsql-jdbc
Hi all,
I am trying to connect to postgresql from a JAVA program.
Previously I used this code:
---------------------------------------------------------------
String classe ="org.postgresql.jdbc3.Jdbc3ConnectionPool";
org.postgresql.jdbc3.Jdbc3ConnectionPool pg;

pg = Class.forName(classe).newInstance();
pg.setServerName(prop.getProperty(serverName));
pg.setPortNumber((new
Integer(prop.getProperty(serverPortNumber)).intValue());
pg.setDatabaseName(prop.getProperty(databaseName));
pg.setUser(login);
pg.setPassword(password);
---------------------------------------------------------------

I then had to change the application in order to use a generic
DataSource (postgresql, oracle, mysql) and noticed that these classes
have different behaviours:
postgreSQL does not have a callable getUrl(), oracle call it getURL,
oracle need a call to getDriverType(), mySQL use setPortNumber(Integer)
instead of setPortNumber(int).

So I tried to use the java reflection to inspect the
org.postgresql.jdbc3.Jdbc3ConnectionPool class (or other classes) and
call all required methods.

The problem is that, when I use this way (a source is attached) I always
get the error:

Exception in thread "main" org.postgresql.util.PSQLException: La
proprietà ``user'' è mancante. E` obbligatoria.
        at
org.postgresql.jdbc1.AbstractJdbc1Connection.openConnection(AbstractJdbc1Connection.java:130)
        at org.postgresql.Driver.connect(Driver.java:138)
        at java.sql.DriverManager.getConnection(DriverManager.java:538)
        at java.sql.DriverManager.getConnection(DriverManager.java:188)
        at
org.postgresql.jdbc2.optional.BaseDataSource.getConnection(BaseDataSource.java:68)
        at
org.postgresql.jdbc2.optional.BaseDataSource.getConnection(BaseDataSource.java:51)
        at
org.postgresql.jdbc3.Jdbc3ConnectionPool.getPooledConnection(Jdbc3ConnectionPool.java:39)
        at dao.jdbc.JDBCMemberDAO.<init>(JDBCMemberDAO.java:29)
        at dao.JDBCDAOFactory.getMemberDAO(JDBCDAOFactory.java:197)
        at test.TestMemberDAO.main(TestMemberDAO.java:34)


that is, in english, "The ``user'' property is missing while it is
mandatory."

Of course the 'setUser()' method is called but it doesn't work.

Do you have any idea about this problem?

I thank you very much,
Giuseppe


Вложения

В списке pgsql-jdbc по дате отправления:

Предыдущее
От: "Sica, David (David)"
Дата:
Сообщение: Re: PostgreSQL 7.4.2 and pg74.1jdbc3.jar
Следующее
От: Kris Jurka
Дата:
Сообщение: Re: problem in connetting using reflection