Обсуждение: set up jdbc
hi, everyone I am a beginner. I want to set up jdbc driver for Postgres 7.2. Can someone give me a step-by-step suggestion. Btw, I have the Postgres DBA account, but I don't have the system administrator account. (I am not sure whether this will make difference). Thanks a lot in advance! Pingdong Ai Portland, OR
Have a peek at http://jdbc.postgresql.org/doc.html#load Tom. On Mon, May 06, 2002 at 04:21:04PM -0700, Pingdong Ai wrote: > hi, everyone > > I am a beginner. I want to set up jdbc driver for Postgres 7.2. Can > someone give me > a step-by-step suggestion. Btw, I have the Postgres DBA account, but I > don't have the > system administrator account. (I am not sure whether this will make > difference). > > Thanks a lot in advance! > > Pingdong Ai > Portland, OR > > > ---------------------------(end of broadcast)--------------------------- > TIP 2: you can get off all lists at once with the unregister command > (send "unregister YourEmailAddressHere" to majordomo@postgresql.org) -- Thomas O'Dowd. - Nooping - http://nooper.com tom@nooper.com - Testing - http://nooper.co.jp/labs
Here is a simple program which takes 4 arguments:
javac DBTest.java      # don't forget to put the jdbc jar in the classpath
java DBTest jdbc:postgresql:your-database-name username password table-name
It connects to the jdbc URL (1st arg) using the username and password (2nd/3rd) and dumps the data in table-name (4th
arg)
Enjoy,
Tim Lucia
import java.sql.*;
public class DBTest
{
    public static void main(String[] args)
    {
        try {
            Class.forName("org.postgresql.Driver");
        }
        catch (Exception e) {
            e.printStackTrace();
        }
        try {
            Connection conn =
                DriverManager.getConnection(args[0], args[1], args[2]);
            Statement s = conn.createStatement();
            dumpSQLTable(s, args[3]);
        }
        catch (Exception e) {
            e.printStackTrace();
        }
    }
    private static void dumpSQLTable(Statement dump, String tableName)
    {
        try {
            int rowCount = 0;
            String query = "SELECT * FROM " + tableName;
            java.sql.ResultSet rs = dump.executeQuery(query);
            ResultSetMetaData rsm = rs.getMetaData();
            final int columns = rsm.getColumnCount();
            System.out.println("<table border='1' cellspacing='1' cellpadding='1'>");
            System.out.println("<caption>" + tableName + "</caption>");
            System.out.println("<tr>");
            for (int i = 1; i <= columns; i++) {
                System.out.println("<td>" + rsm.getColumnLabel(i) + "</td>");
            }
            System.out.println("</tr>");
            while (rs.next()) {
                System.out.println("<tr>");
                for (int i = 1 ; i <= columns; i++) {
                    System.out.println("<td>" + rs.getObject(i) + "</td>");
                }
                rowCount++;
                System.out.println("</tr>");
            }
            System.out.println("<tr><td colspan='" + columns + "'>Rows = " + rowCount +
                       "</td></tr>");
            System.out.println("</table>");
        }
        catch (SQLException sqle) {
            System.out.println("Exception: " + sqle.getMessage());
        }
    }
}
-----Original Message-----
From: Pingdong Ai [mailto:pingdong@cs.pdx.edu]
Sent: Monday, May 06, 2002 7:21 PM
To: pgsql-jdbc@postgresql.org
Subject: [JDBC] set up jdbc
hi, everyone
I am a beginner. I want to set up jdbc driver for Postgres 7.2.   Can
someone give me
a step-by-step suggestion.  Btw, I have the Postgres DBA account, but I
don't have the
system administrator account. (I am not sure whether this will make
difference).
Thanks a lot in advance!
Pingdong Ai
Portland, OR
---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
    (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)
			
		Although it is not a complete set of setup instructions, you'll find notes about commonly encountered problems here: http://www.fankhausers.com/postgresql/jdbc/ -Nick > -----Original Message----- > From: pgsql-jdbc-owner@postgresql.org > [mailto:pgsql-jdbc-owner@postgresql.org]On Behalf Of Pingdong Ai > Sent: Monday, May 06, 2002 6:21 PM > To: pgsql-jdbc@postgresql.org > Subject: [JDBC] set up jdbc > > > hi, everyone > > I am a beginner. I want to set up jdbc driver for Postgres 7.2. Can > someone give me > a step-by-step suggestion. Btw, I have the Postgres DBA account, but I > don't have the > system administrator account. (I am not sure whether this will make > difference). > > Thanks a lot in advance! > > Pingdong Ai > Portland, OR > > > ---------------------------(end of broadcast)--------------------------- > TIP 2: you can get off all lists at once with the unregister command > (send "unregister YourEmailAddressHere" to majordomo@postgresql.org) >