Connecting to a PostgreSQL database

Stimulsoft Reports.JAVA discussion
Post Reply
thomasn
Posts: 1
Joined: Thu Aug 06, 2015 3:23 pm

Connecting to a PostgreSQL database

Post by thomasn »

Has anyone had any luck connecting to a PostgreSQL database from the web designer? I'm using the designer sample code that comes with the install, added the PostgreSQL JDBC jar and run it. It loads and presents the designer with the demo XML data source and sample report and all looks good, but when I try to add a connection to a PostgreSQL database I get the completely useless error "class java.lang.NullPointerException" when I click Test.

I know it's picking up the driver because if I exclude it from the classpath I get the equally vague error "org.postgresql.Driver". If anyone from Stimulsoft is reading this, it would be useful if you printed the exception message (Exception.getMessage()) instead of the class name!

I can Ok that dialog and it accepts the connection but if I try to create a data source using that connection I get the same error message. However, this time I get a stack trace in the console that I can debug.

Code: Select all

java.lang.NullPointerException
	at java.util.Hashtable.put(Hashtable.java:514)
	at java.util.Properties.setProperty(Properties.java:161)
	at com.stimulsoft.webdesigner.helper.StiDictionaryHelper.getConnection(StiDictionaryHelper.java:1962)
	at com.stimulsoft.webdesigner.helper.StiDictionaryHelper.getDatabaseData(StiDictionaryHelper.java:1992)
	at com.stimulsoft.webdesigner.helper.StiDictionaryHelper.getDatabaseData(StiDictionaryHelper.java:1974)
	at com.stimulsoft.webdesigner.StiWebDesigner.designerEventResult(StiWebDesigner.java:833)
	at com.stimulsoft.webdesigner.servlet.StiWebDesignerActionServlet.processing(StiWebDesignerActionServlet.java:56)
	at com.stimulsoft.webdesigner.servlet.StiWebDesignerActionServlet.doPost(StiWebDesignerActionServlet.java:45)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:644)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
	at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:516)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1086)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:659)
	at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:285)
	at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2431)
	at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2420)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Thread.java:744)
It's difficult to figure out what's happening without the Stimulsoft source but it looks like it might be trying to put a null object into a Properties object, which extends a Hashtable so will cause an NPE. From the IntelliJ debugger it looks like it's setting the attribute "user" to null. The password object is an empty string, which is fine. There is nowhere to set a username or password in the dialog as checking the "Prompt User Name and Password" has no effect. In fact, if I edit the connection I can change the name, alias and connection string but it doesn't remember if I checked the "Prompt User Name and Password" box. It's always unchecked when I re-open it.
Vadim
Posts: 409
Joined: Tue Apr 23, 2013 11:23 am

Re: Connecting to a PostgreSQL database

Post by Vadim »

Hello.
You should use connection string like this:

Code: Select all

User ID=postgres;Password=password;Host=localhost;Port=5432;Database=postgres;
Post Reply