Re: sample JSP code connecting to PostgreSQL - Mailing list pgsql-jdbc

From Andres Ledesma
Subject Re: sample JSP code connecting to PostgreSQL
Date
Msg-id 200302241001.58887.aledes@telefonica.net
Whole thread Raw
In response to sample JSP code connecting to PostgreSQL  (Roj Niyogi <niyogi@pghoster.com>)
List pgsql-jdbc
On Monday 24 February 2003 08:50, you wrote:
> Hi folks,
>
> I'm wondering if anybody would be pleasant enough to give me a complete
> script containing JSP code that makes a simple connection to a
> PostgreSQL database, retrieves data and dumps to screen.
>
> I must be dumb not to be able to find this information anywhere on the
> net. :(
>
> Regards,
> Roj

Hope this help ...to you or anybody else..

Best regards,

Andrewle

import java.sql.*;

class gettablerows{

    public static void main(String args[])
    {


        String url = "jdbc:postgresql://localhost/database";
        Connection con;
        ResultSet rs;
        String s;
        String sqlstr = "SELECT f1, f2, f3 FROM table";

        try
        {
            Class.forName("org.postgresql.Driver");
        }
        catch(java.lang.ClassNotFoundException e)
        {
            System.err.print("ClassNotFoundException: ");
            System.err.println(e.getMessage());
        }

        try
        {
            con = DriverManager.getConnection(url,"postgres", "");

            st = con.createStatement();
            rs = st.executeQuery(sqlstr);

            System.out.println("Rows are :");
            while(rs.next())
            {
                s = rs.getString(1);
                  System.out.println(s);
            }
            System.out.println(mn.gname());
                 rs.close();
            st.close();
            con.close();

        }
        catch(SQLException ex)
        {
            System.err.println("SQLException: " + ex.getMessage());
        }

    }

}





pgsql-jdbc by date:

Previous
From: Tony Grant
Date:
Subject: Re: sample JSP code connecting to PostgreSQL
Next
From: "carloszaparoli"
Date:
Subject: Field BLOB