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:

/*
 * Query0.java
 *
 * Created on December 23, 2000, 12:42 PM
 */

import java.io.*;
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 {
        res.setContentType("text/html");
        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
work
    }

    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 + "
</TITLE></HEAD>");
        out.println("<BODY><H1>" + title + "</H1>");
        out.println("<H2>Version 1.0g</H2>");
        out.println(queryResult);
        out.println("</BODY></HTML>");
    }

    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 {
            Class.forName(driverName);
            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 (!rs.next()) {
                return "no such name as " + key;
            }
            return rs.getString(1);
        }
        catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
}

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

Reply via email to