Thread: jsp postgresql problems
This is my code:
<%@ page import ="java.sql.*" %>
<%
Driver drv = (Driver)Class.forName("org.postgresql.Driver").newInstance(); Connection conn = java.sql.DriverManager.getConnection("jdbc:postgresql://localhost:5432/db_name", "username", "password");
%>
now the stack error i am running into is:
Connection refused. Check that the hostname and port is correct, and that the postmaster is running with the -i flag, which enables TCP/IP networking.
i know its not the server or the way it is setup cause i can connect to the DB in ASP? so what is wrong with the JSP? i do have the drivers installed for postgresql cause the first error before this i was getting was that it couldn't find the drivers (silly me forgot to reset the server).
anyone help ?
Thanks
A couple of thoughts/questions- You don't need to instantiate the driver if you load it in your code, so you can use this instead of the code you posted: <% Class.forName("org.postgresql.Driver"); Connection conn = java.sql.DriverManager.getConnection("jdbc:postgresql://localhost:5432/db_na me", "username", "password"); %> Does ASP actually use TCP/IP to communicate with the DB? (I'm not very familiar with it.) Have you tried just a plain vanilla connection to the database that doesn't involve a JSP? Doing that would help isolate the cause to something that is servlet/JSP-related or something that is JDBC-related. -NickF -------------------------------------------------------------------------- Nick Fankhauser nickf@ontko.com Phone 1.765.935.4283 Fax 1.765.962.9788 Ray Ontko & Co. Software Consulting Services http://www.ontko.com/ -----Original Message----- From: pgsql-jdbc-owner@postgresql.org [mailto:pgsql-jdbc-owner@postgresql.org]On Behalf Of Ryan Skoblenick Sent: Sunday, March 03, 2002 6:52 PM To: pgsql-jdbc@postgresql.org Subject: [JDBC] jsp postgresql problems This is my code: <%@ page import ="java.sql.*" %> <% Driver drv = (Driver)Class.forName("org.postgresql.Driver").newInstance(); Connection conn = java.sql.DriverManager.getConnection("jdbc:postgresql://localhost:5432/db_na me", "username", "password"); %> now the stack error i am running into is: Connection refused. Check that the hostname and port is correct, and that the postmaster is running with the -i flag, which enables TCP/IP networking. i know its not the server or the way it is setup cause i can connect to the DB in ASP? so what is wrong with the JSP? i do have the drivers installed for postgresql cause the first error before this i was getting was that it couldn't find the drivers (silly me forgot to reset the server). anyone help ? Thanks
JSP (any Java) will use TCP/IP via the driver... you may need to tweak your pg_hba.conf file to allow TCP/IP connections from localhost, or add the -i flag when starting postmaster up as this enables the server socket. Cheers, Joe PS You can omit the port number 5432 from the connection string as this is the default, even 'jdbc:postgresql:db_name' will work for local connections (and as Nick mentioned you don't need the newInstance() method, drivers you do need it for are breaking the spec). -----Original Message----- From: pgsql-jdbc-owner@postgresql.org [mailto:pgsql-jdbc-owner@postgresql.org]On Behalf Of Ryan Skoblenick Sent: Monday, 4 March 2002 10:52 To: pgsql-jdbc@postgresql.org Subject: [JDBC] jsp postgresql problems This is my code: <%@ page import ="java.sql.*" %> <% Driver drv = (Driver)Class.forName("org.postgresql.Driver").newInstance(); Connection conn = java.sql.DriverManager.getConnection("jdbc:postgresql://localhost:5432/db_ name", "username", "password"); %> now the stack error i am running into is: Connection refused. Check that the hostname and port is correct, and that the postmaster is running with the -i flag, which enables TCP/IP networking. i know its not the server or the way it is setup cause i can connect to the DB in ASP? so what is wrong with the JSP? i do have the drivers installed for postgresql cause the first error before this i was getting was that it couldn't find the drivers (silly me forgot to reset the server). anyone help ? Thanks
Attachment
hi group !! firstly i shud say that this small piece of code killed me...and finally figured out what was happening.. thanz Dave and Nick for ur support...the problem was with the driver... i downloaded more than 4 drivers and checked them and finally found that pgjdbc1.jar is right fellow.... i will have a peaceful nightz sleep today
Sriram, That's great, so how do we go about fixing the driver? Where did you get pgjdbc1.jar, the 1 in the name implies that it is a jdk1.1 driver? Are you using jdk1.1, or jdk1.2? Dave -----Original Message----- From: pgsql-jdbc-owner@postgresql.org [mailto:pgsql-jdbc-owner@postgresql.org] On Behalf Of # sriram # Sent: Friday, March 08, 2002 6:34 AM To: pgsql-jdbc@postgresql.org Subject: [JDBC] weird problems solved ?? hi group !! firstly i shud say that this small piece of code killed me...and finally figured out what was happening.. thanz Dave and Nick for ur support...the problem was with the driver... i downloaded more than 4 drivers and checked them and finally found that pgjdbc1.jar is right fellow.... i will have a peaceful nightz sleep today ---------------------------(end of broadcast)--------------------------- TIP 6: Have you searched our list archives? http://archives.postgresql.org