Re: sample JSP code connecting to PostgreSQL

From: Andres Ledesma <aledes(at)telefonica(dot)net>
To: Roj Niyogi <niyogi(at)pghoster(dot)com>
Cc: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: sample JSP code connecting to PostgreSQL
Date: 2003-02-24 09:01:58
Message-ID: 200302241001.58887.aledes@telefonica.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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());
}

}

}

In response to

Browse pgsql-jdbc by date

  From Date Subject
Next Message carloszaparoli 2003-02-24 12:38:28 Field BLOB
Previous Message Roj Niyogi 2003-02-24 07:50:38 sample JSP code connecting to PostgreSQL