Re: set up jdbc

Поиск
Список
Период
Сортировка
Искать
От
Tim Lucia
Тема
Re: set up jdbc
Дата
в 10:06:44
Msg-id
7BFCE5F1EF28D64198522688F5449D5A3D0214@xchangeserver2.storigen.com
Список
Дерево обсуждения
Re: set up jdbc "Tim Lucia" <Tim.Lucia@storigen.com>
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("");
            System.out.println("");
            System.out.println("");
            for (int i = 1; i <= columns; i++) {
                System.out.println("");
            }
            System.out.println("");
            while (rs.next()) {
                System.out.println("");
                for (int i = 1 ; i <= columns; i++) {
                    System.out.println("");
                }
                rowCount++;
                System.out.println("");
            }
            System.out.println("");
            System.out.println("
" + tableName + "
" + rsm.getColumnLabel(i) + "
" + rs.getObject(i) + "
Rows = " + rowCount + "
"); } 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)
В списке pgsql-jdbc по дате отправления
От: Thomas De Vos
Дата:
Сообщение: Encoding
От: Nick Fankhauser
Дата:
Сообщение: Re: set up jdbc
FAQ