Skip site navigation (1) Skip section navigation (2)

Java and Postgresql

From: "Mike S(dot) Avelar" <mavelar(at)sympatico(dot)ca>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Java and Postgresql
Date: 2000-12-24 03:13:03
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-hackers
Hey... I'm just learning how to do all this db stuff and I'm kinda
crippled because I've never used SQL.

Here is what I'm doing. I've got pgaccess working, it works greate, I
create databases and sql queries with it.

I've got JRun running for my servlet engine, it also works great.

Now when try to connect to my database through java... nothing happens.

I'm using the following code to connect to the db:

 * Created on December 23, 2000, 12:42 PM

import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;

 * @author  avelar
 * @version
public class Query0 extends HttpServlet {

    /** Creates new Query0 */
    public Query0() {

    public void doGet (HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
        PrintWriter out = res.getWriter();
        String theName = req.getParameter("theName"); //theName is the
NAME attribute of the input field in submitting form
        String queryResult = lookup(theName); // does all database work
        String title = "Query Result: Phone Number for " + theName;
        wrapInHTMLPage(out, queryResult, title); // does all output HTML

    public void doPost (HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
        doGet(req, res);

    public void wrapInHTMLPage(PrintWriter out, String queryResult,
String title) throws IOException {
        out.println("<HTML><HEAD><TITLE> " + title + "
        out.println("<BODY><H1>" + title + "</H1>");
        out.println("<H2>Version 1.0g</H2>");

    public String lookup (String key) {
        // variables for data base work
        String driverName = "postgresql.Driver";
        String dbURL = "jdbc:postgresql://localhost5432/phonebook";
        String queryString = "select t0.\"theName\",t0.\"theAddress\"
from \"PhoneBookTbl\" t0 order by t0.\"theName\" desc";

        try {
            Connection con = DriverManager.getConnection(dbURL,
"avelar", "daewoo");
            Statement stmt = con.createStatement();
            ResultSet rs = stmt.executeQuery(queryString);
            if (null == rs) {
                return "db failure on " + key;
            if (! {
                return "no such name as " + key;
            return rs.getString(1);
        catch (Exception e) {
            return null;

I've made sure that the pg_hba.conf file is setup properly... what am I

pgsql-hackers by date

Next:From: Tom LaneDate: 2000-12-24 03:58:10
Subject: Re: Re: Too many open files (was Re: spinlock problems reported earlier)
Previous:From: Tatsuo IshiiDate: 2000-12-24 02:42:45
Subject: Re: Re: Too many open files (was Re: spinlock problems reported earlier)

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group