I'm am currently trying to learn Java and want to connect to a Postgresql database.
I am using a simple JSP page and a bean which contains all database functions. This is set up in Tomcat and JDK/1.6.0. Everything works fine but the connection itself, for some reason it throws a null value.
I suspect that the problem is the connection configuration, in tomcat/conf/context.xml.
Connecting to the database from terminal works fine, using psql -h etc...
This is what I have:
Running login.jsp returns error here:
What am I doing wrong? Help is very much appreciated.
The code above throws the exception when creating connection and How could one possibly know what it is unless you print it out.
Empty Catch() statement are programmers 'Devil' , it hides everything and shows everythig as normal
I tried the code with the new catch statements. The strange thing is that it no longer returns an error at all, the page loads fine and the function returns false. (It should return true)
This is the complete code for db.java now:
I don't know if there is a way to make the function print my query, but System.out.println did not work (nothing was printed).
Though, I am pretty sure the sql is ok, because when I changed the last return to true, the whole function returned true.
Btw, the reference looked good, I have read the part about Postgresql but I don't think I have missed anything in the setup.
To me, it still looks like a configuration problem, like if it doesnt find the database host.
Thats 100% right. but we have been trying to catch the error and found out whats the misconfiguration. I wonder how your code manages to escape exceptions and show error on different line on different run..
I m not able to donwload the file Catalina.out. Did you look in to that ? found anything ? Is it printing SOPs ? Unless the i see the SOP or log , cant predict anything..
A few problems:
1) You are ignoring the SQL Exception thrown on creating the connection. It's not valid to continue so you might as well take the user to an error page when this happens.
2) It's traditional to use an if statement in the finally block.
3) You need to close the connection when done with it not after the first query.