Re: sample JSP code connecting to PostgreSQL
| От | Andres Ledesma | 
|---|---|
| Тема | Re: sample JSP code connecting to PostgreSQL | 
| Дата | |
| Msg-id | 200302241001.58887.aledes@telefonica.net обсуждение исходный текст | 
| Ответ на | sample JSP code connecting to PostgreSQL (Roj Niyogi <niyogi@pghoster.com>) | 
| Список | 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 по дате отправления: