problem in connetting using reflection

From: Giuseppe Sacco <giuseppe(at)eppesuigoccas(dot)homedns(dot)org>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: problem in connetting using reflection
Date: 2004-04-11 00:16:50
Message-ID: 1081642610.713.23.camel@eppesuig3
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Attachment Content-Type Size
JDBCDAOFactory.java text/x-java 6.1 KB
my.properties text/plain 459 bytes

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Kris Jurka 2004-04-11 01:28:51 Re: problem in connetting using reflection
Previous Message Sica, David (David) 2004-04-10 22:34:27 Re: PostgreSQL 7.4.2 and pg74.1jdbc3.jar